mirror of
https://github.com/zebrajr/immich.git
synced 2025-12-06 00:20:20 +01:00
27 lines
844 B
TypeScript
27 lines
844 B
TypeScript
import { asKey } from 'src/sql-tools/helpers';
|
|
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')) {
|
|
const table = builder.getTableByObject(object);
|
|
if (!table) {
|
|
builder.warnMissingTable('@Check', object);
|
|
continue;
|
|
}
|
|
|
|
const tableName = table.name;
|
|
|
|
table.constraints.push({
|
|
type: ConstraintType.CHECK,
|
|
name: options.name || asCheckConstraintName(tableName, options.expression),
|
|
tableName,
|
|
expression: options.expression,
|
|
synchronize: options.synchronize ?? true,
|
|
});
|
|
}
|
|
};
|
|
|
|
const asCheckConstraintName = (table: string, expression: string) => asKey('CHK_', table, [expression]);
|