2025-07-03 10:59:17 -04:00
|
|
|
import { ConstraintType, Processor } from 'src/sql-tools/types';
|
2025-04-07 15:12:12 -04:00
|
|
|
|
2025-07-08 08:17:40 -04:00
|
|
|
export const processCheckConstraints: Processor = (ctx, items) => {
|
2025-04-07 15:12:12 -04:00
|
|
|
for (const {
|
|
|
|
|
item: { object, options },
|
|
|
|
|
} of items.filter((item) => item.type === 'checkConstraint')) {
|
2025-07-08 08:17:40 -04:00
|
|
|
const table = ctx.getTableByObject(object);
|
2025-04-07 15:12:12 -04:00
|
|
|
if (!table) {
|
2025-07-08 08:17:40 -04:00
|
|
|
ctx.warnMissingTable('@Check', object);
|
2025-04-07 15:12:12 -04:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const tableName = table.name;
|
|
|
|
|
|
|
|
|
|
table.constraints.push({
|
2025-07-03 10:59:17 -04:00
|
|
|
type: ConstraintType.CHECK,
|
2025-07-11 11:35:10 -04:00
|
|
|
name: options.name || ctx.getNameFor({ type: 'check', tableName, expression: options.expression }),
|
2025-04-07 15:12:12 -04:00
|
|
|
tableName,
|
|
|
|
|
expression: options.expression,
|
|
|
|
|
synchronize: options.synchronize ?? true,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|