Skip to content

Commit

Permalink
fix: null contraint with mediaAddedAt; fix psql col type
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-carrot committed Dec 4, 2024
1 parent 0154e6b commit 6957b76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion server/entity/Media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down
2 changes: 1 addition & 1 deletion server/utils/DbColumnHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6957b76

Please sign in to comment.