Files
immich/server/src/sql-tools/processors/check-constraint.processor.ts

27 lines
844 B
TypeScript
Raw Normal View History

2025-04-17 14:41:06 -04:00
import { asKey } from 'src/sql-tools/helpers';
2025-07-03 10:59:17 -04:00
import { ConstraintType, Processor } from 'src/sql-tools/types';
export const processCheckConstraints: Processor = (builder, items) => {
for (const {
item: { object, options },
} of items.filter((item) => item.type === 'checkConstraint')) {
2025-07-03 10:59:17 -04:00
const table = builder.getTableByObject(object);
if (!table) {
2025-07-03 10:59:17 -04:00
builder.warnMissingTable('@Check', object);
continue;
}
const tableName = table.name;
table.constraints.push({
2025-07-03 10:59:17 -04:00
type: ConstraintType.CHECK,
name: options.name || asCheckConstraintName(tableName, options.expression),
tableName,
expression: options.expression,
synchronize: options.synchronize ?? true,
});
}
};
2025-04-17 14:41:06 -04:00
const asCheckConstraintName = (table: string, expression: string) => asKey('CHK_', table, [expression]);