fix: null contraint with mediaAddedAt; fix psql col type

This commit is contained in:
dr-carrot
2024-12-04 18:21:20 -05:00
parent 0154e6b538
commit 6957b7606e
2 changed files with 15 additions and 2 deletions

View File

@@ -132,10 +132,23 @@ class Media {
@UpdateDateColumn()
public updatedAt: Date;
/**
* The `lastSeasonChange` column stores the date and time when the media was added to the library.
* It needs to be database-aware because SQLite supports `datetime` while PostgreSQL supports `timestamp with timezone (timestampz)`.
*/
@DbAwareColumn({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' })
public lastSeasonChange: Date;
@DbAwareColumn({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' })
/**
* The `mediaAddedAt` column stores the date and time when the media was added to the library.
* It needs to be database-aware because SQLite supports `datetime` while PostgreSQL supports `timestamp with timezone (timestampz)`.
* This column is nullable because it can be null when the media is not yet synced to the library.
*/
@DbAwareColumn({
type: 'datetime',
default: () => 'CURRENT_TIMESTAMP',
nullable: true,
})
public mediaAddedAt: Date;
@Column({ nullable: true, type: 'int' })

View File

@@ -2,7 +2,7 @@ import { isPgsql } from '@server/datasource';
import type { ColumnOptions, ColumnType } from 'typeorm';
import { Column } from 'typeorm';
const pgTypeMapping: { [key: string]: ColumnType } = {
datetime: 'timestamp without time zone',
datetime: 'timestamp with time zone',
};
export function resolveDbType(pgType: ColumnType): ColumnType {