mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 19:16:08 +00:00
refactor(db): split the Postgres schema adjustments by concern
schema-adjust.ts mixed the statement splitter, the trigger ports and the column adjustments, and every caller repeated `meta.props as EntityProperty[] as ColumnMeta[]` to reach them. Now: - sql-split.ts holds splitStatements. Its scope is written down: `;` outside quotes, '/" quoted text and the $$ body, and the session-setting lines it drops. A tagged dollar quote ($tag$) is refused with an error instead of being split inside, which the splitter could not do correctly. - postgres-triggers.ts holds the hand-written trigger ports, which the baseline and the parity test read by name. - schema-adjust.ts holds the column adjustments. applyPostgresColumnAdjustments (renamed from adjustColumns, which hid that it mutates its input) takes an entity's props directly: ColumnMeta now reads customType as unknown, so the entity's property metadata satisfies it without a cast. Each adjustment is a small function that returns whether it changed the column. The timestamp check is now `instanceof DbTimestampType` rather than a compare on the constructor's name, which would have broken silently on a rename.
This commit is contained in:
@@ -20,9 +20,10 @@
|
||||
* - dropping a trigger the entities cannot carry: only the triggers ported by
|
||||
* hand (POSTGRES_TRIGGERS), by exact name, and each of them must exist.
|
||||
*/
|
||||
import { adjustColumns, POSTGRES_TRIGGERS, type ColumnMeta } from '../../src/db/engine/postgres/schema-adjust';
|
||||
import { POSTGRES_TRIGGERS } from '../../src/db/engine/postgres/postgres-triggers';
|
||||
import { applyPostgresColumnAdjustments } from '../../src/db/engine/postgres/schema-adjust';
|
||||
import { ALL_ENTITIES } from '../../src/db/entities';
|
||||
import type { EntityProperty, Transaction } from '@mikro-orm/core';
|
||||
import type { Transaction } from '@mikro-orm/core';
|
||||
import { MikroORM } from '@mikro-orm/postgresql';
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
@@ -100,7 +101,7 @@ describe('PARITY-PG', () => {
|
||||
});
|
||||
try {
|
||||
for (const meta of orm.getMetadata().getAll().values()) {
|
||||
adjustColumns(meta.props as EntityProperty[] as ColumnMeta[]);
|
||||
applyPostgresColumnAdjustments(meta.props);
|
||||
}
|
||||
const live = await liveSets(orm);
|
||||
const statements = (await orm.schema.getUpdateSchemaSQL({ wrap: false }))
|
||||
|
||||
Reference in New Issue
Block a user