mirror of
https://github.com/immich-app/immich.git
synced 2025-05-30 19:54:52 -04:00
27 lines
923 B
TypeScript
27 lines
923 B
TypeScript
import { onMissingTable, resolveTable } from 'src/sql-tools/from-code/processors/table.processor';
|
|
import { Processor } from 'src/sql-tools/from-code/processors/type';
|
|
import { asCheckConstraintName } from 'src/sql-tools/helpers';
|
|
import { DatabaseConstraintType } from 'src/sql-tools/types';
|
|
|
|
export const processCheckConstraints: Processor = (builder, items) => {
|
|
for (const {
|
|
item: { object, options },
|
|
} of items.filter((item) => item.type === 'checkConstraint')) {
|
|
const table = resolveTable(builder, object);
|
|
if (!table) {
|
|
onMissingTable(builder, '@Check', object);
|
|
continue;
|
|
}
|
|
|
|
const tableName = table.name;
|
|
|
|
table.constraints.push({
|
|
type: DatabaseConstraintType.CHECK,
|
|
name: options.name || asCheckConstraintName(tableName, options.expression),
|
|
tableName,
|
|
expression: options.expression,
|
|
synchronize: options.synchronize ?? true,
|
|
});
|
|
}
|
|
};
|