fix(db): generator keeps NOT NULL boolean defaults; fails if a JSON interface import survives

This commit is contained in:
jubnl
2026-09-22 10:39:07 +02:00
parent 257529b250
commit 7534c2f903
2 changed files with 8 additions and 1 deletions
+7 -1
View File
@@ -612,7 +612,8 @@ export interface DefaultFixup {
}
/** A raw SQL default that is a plain literal (number or single-quoted string) rather than an expression like `CURRENT_TIMESTAMP`. */
const PLAIN_LITERAL_DEFAULT_RE = /^-?\d+(\.\d+)?$|^'.*'$/;
// Numbers, quoted strings and the booleans RULE1c coerces a NOT NULL boolean default into.
const PLAIN_LITERAL_DEFAULT_RE = /^-?\d+(\.\d+)?$|^'.*'$|^(?:true|false)$/;
/**
* Rule (metadata level for detection + clearing `defaultRaw`; text level for
@@ -1006,6 +1007,11 @@ export function injectJsonInterfaces(source: string, fixups: readonly JsonColumn
const escaped = escapeRegExp(typeName);
const bogusImportRe = new RegExp(`^import \\{ ${escaped} \\} from '\\./${escaped}\\.entity';\\n`, 'm');
result = result.replace(bogusImportRe, '');
// The generator resolves an unknown type name to a sibling entity import;
// nothing else may still import the interface from a file that never exists.
if (new RegExp(`from '\\./${escaped}\\.entity'`).test(result)) {
throw new Error(`generate-entities: injectJsonInterfaces left an import of "${typeName}" from a nonexistent ./${typeName}.entity file.`);
}
}
const classRe = /^export class \w+ /m;
const match = classRe.exec(result);
@@ -855,6 +855,7 @@ describe('generateEntities — migrations path is anchored to SERVER_ROOT, not c
'MIGPATH-001: generation still finds migrations when run from the repo root instead of server/',
async () => {
const originalCwd = process.cwd();
// process.chdir() is only safe because vitest.config.ts uses pool: 'forks' (a worker thread cannot chdir).
process.chdir(path.join(__dirname, '../../../..')); // server/tests/unit/db -> repo root
try {
const { files } = await generateEntities();