Files
jellyseerr/server/entity/DiscoverSlider.ts
fallenbagel 8da1c92923 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>
2025-05-10 03:38:22 +08:00

69 lines
1.7 KiB
TypeScript

import type { DiscoverSliderType } from '@server/constants/discover';
import { defaultSliders } from '@server/constants/discover';
import { getRepository } from '@server/datasource';
import logger from '@server/logger';
import { DbAwareColumn } from '@server/utils/DbColumnHelper';
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
class DiscoverSlider {
public static async bootstrapSliders(): Promise<void> {
const sliderRepository = getRepository(DiscoverSlider);
for (const slider of defaultSliders) {
const existingSlider = await sliderRepository.findOne({
where: {
type: slider.type,
},
});
if (!existingSlider) {
logger.info('Creating built-in discovery slider', {
label: 'Discover Slider',
slider,
});
await sliderRepository.save(new DiscoverSlider(slider));
}
}
}
@PrimaryGeneratedColumn()
public id: number;
@Column({ type: 'int' })
public type: DiscoverSliderType;
@Column({ type: 'int' })
public order: number;
@Column({ default: false })
public isBuiltIn: boolean;
@Column({ default: true })
public enabled: boolean;
@Column({ nullable: true })
// Title is not required for built in sliders because we will
// use translations for them.
public title?: string;
@Column({ nullable: true })
public data?: string;
@DbAwareColumn({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' })
public createdAt: Date;
@DbAwareColumn({
type: 'datetime',
default: () => 'CURRENT_TIMESTAMP',
onUpdate: 'CURRENT_TIMESTAMP',
})
public updatedAt: Date;
constructor(init?: Partial<DiscoverSlider>) {
Object.assign(this, init);
}
}
export default DiscoverSlider;