mirror of
https://github.com/seerr-team/seerr.git
synced 2025-12-23 23:58:07 -05:00
* fix(entity): use TIMESTAMPTZ in Postgres and sort issue comments oldest-first Switch key datetime columns to TIMESTAMPTZ for proper UTC handling (“just now”) and sort issue comments on load so the original description stays first and in proper sorted order in fix-pgsql-timezone fixes #1569, fixes #1568 * refactor(migration): manually rewrite pgsql migration to preserve existing data Typeorm generated migration was dropping the entire column thus leading to data loss so this is an attempt at manually rewriting the migration to preserve the data * refactor(migrations): rename to be consistent with other migration files * fix: use id to order instead of createdAt to avoid non-existant createdAt --------- Co-authored-by: Gauthier <mail@gauthierth.fr>
79 lines
1.7 KiB
TypeScript
79 lines
1.7 KiB
TypeScript
import type { IssueType } from '@server/constants/issue';
|
|
import { IssueStatus } from '@server/constants/issue';
|
|
import { DbAwareColumn } from '@server/utils/DbColumnHelper';
|
|
import {
|
|
AfterLoad,
|
|
Column,
|
|
Entity,
|
|
ManyToOne,
|
|
OneToMany,
|
|
PrimaryGeneratedColumn,
|
|
} from 'typeorm';
|
|
import IssueComment from './IssueComment';
|
|
import Media from './Media';
|
|
import { User } from './User';
|
|
|
|
@Entity()
|
|
class Issue {
|
|
@PrimaryGeneratedColumn()
|
|
public id: number;
|
|
|
|
@Column({ type: 'int' })
|
|
public issueType: IssueType;
|
|
|
|
@Column({ type: 'int', default: IssueStatus.OPEN })
|
|
public status: IssueStatus;
|
|
|
|
@Column({ type: 'int', default: 0 })
|
|
public problemSeason: number;
|
|
|
|
@Column({ type: 'int', default: 0 })
|
|
public problemEpisode: number;
|
|
|
|
@ManyToOne(() => Media, (media) => media.issues, {
|
|
eager: true,
|
|
onDelete: 'CASCADE',
|
|
})
|
|
public media: Media;
|
|
|
|
@ManyToOne(() => User, (user) => user.createdIssues, {
|
|
eager: true,
|
|
onDelete: 'CASCADE',
|
|
})
|
|
public createdBy: User;
|
|
|
|
@ManyToOne(() => User, {
|
|
eager: true,
|
|
onDelete: 'CASCADE',
|
|
nullable: true,
|
|
})
|
|
public modifiedBy?: User;
|
|
|
|
@OneToMany(() => IssueComment, (comment) => comment.issue, {
|
|
cascade: true,
|
|
eager: true,
|
|
})
|
|
public comments: IssueComment[];
|
|
|
|
@DbAwareColumn({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' })
|
|
public createdAt: Date;
|
|
|
|
@DbAwareColumn({
|
|
type: 'datetime',
|
|
default: () => 'CURRENT_TIMESTAMP',
|
|
onUpdate: 'CURRENT_TIMESTAMP',
|
|
})
|
|
public updatedAt: Date;
|
|
|
|
@AfterLoad()
|
|
sortComments() {
|
|
this.comments?.sort((a, b) => a.id - b.id);
|
|
}
|
|
|
|
constructor(init?: Partial<Issue>) {
|
|
Object.assign(this, init);
|
|
}
|
|
}
|
|
|
|
export default Issue;
|