fix(entity): use TIMESTAMPTZ in Postgres and sort issue comments oldest-first (#1654)

* 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>
This commit is contained in:
fallenbagel
2025-05-10 03:38:22 +08:00
committed by GitHub
parent 70a28dd1e3
commit 8da1c92923
13 changed files with 320 additions and 78 deletions

View File

@@ -5,15 +5,14 @@ import Media from '@server/entity/Media';
import { User } from '@server/entity/User';
import type { WatchlistItem } from '@server/interfaces/api/discoverInterfaces';
import logger from '@server/logger';
import { DbAwareColumn } from '@server/utils/DbColumnHelper';
import {
Column,
CreateDateColumn,
Entity,
Index,
ManyToOne,
PrimaryGeneratedColumn,
Unique,
UpdateDateColumn,
} from 'typeorm';
import type { ZodNumber, ZodOptional, ZodString } from 'zod';
@@ -56,10 +55,14 @@ export class Watchlist implements WatchlistItem {
})
public media: Media;
@CreateDateColumn()
@DbAwareColumn({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' })
public createdAt: Date;
@UpdateDateColumn()
@DbAwareColumn({
type: 'datetime',
default: () => 'CURRENT_TIMESTAMP',
onUpdate: 'CURRENT_TIMESTAMP',
})
public updatedAt: Date;
constructor(init?: Partial<Watchlist>) {