You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
overseerr/server/utils/DbColumnHelper.ts

23 lines
634 B

import type { ColumnOptions, ColumnType } from 'typeorm';
import { Column } from 'typeorm';
export const isPostgres = process.env.DB_TYPE === 'postgres';
const pgTypeMapping: { [key: string]: ColumnType } = {
datetime: 'timestamp with time zone',
};
export function resolveDbType(pgType: ColumnType): ColumnType {
if (isPostgres && pgType.toString() in pgTypeMapping) {
return pgTypeMapping[pgType.toString()];
}
return pgType;
}
export function DbAwareColumn(columnOptions: ColumnOptions) {
if (columnOptions.type) {
columnOptions.type = resolveDbType(columnOptions.type);
}
return Column(columnOptions);
}