T-36: M1.1a — Security master DDL migration (11 tables on the master track)
This commit is contained in:
parent
3e1f108c6f
commit
8326d24957
6 changed files with 914 additions and 27 deletions
|
|
@ -4,7 +4,7 @@ import { afterEach, describe, expect, test } from 'bun:test';
|
|||
import type { PoolClient } from 'pg';
|
||||
import { Pool } from 'pg';
|
||||
import { getLogger, setLoggerConfig } from '@stock-bot/logger';
|
||||
import { PostgreSQLClient } from '@stock-bot/postgres';
|
||||
import { PostgreSQLClient, runPostgresMigrations } from '@stock-bot/postgres';
|
||||
import { runMigrations } from '../../apps/stock/web-api/src/migrations/migration-runner';
|
||||
|
||||
setLoggerConfig({ logLevel: 'fatal', logConsole: false });
|
||||
|
|
@ -133,6 +133,7 @@ async function fixture() {
|
|||
return {
|
||||
queries,
|
||||
run: () => runMigrations({ postgres, logger }),
|
||||
runTrack: (track: 'master' | 'research' | 'all') => runPostgresMigrations(postgres, { track }),
|
||||
};
|
||||
};
|
||||
const recorded = async () =>
|
||||
|
|
@ -365,4 +366,62 @@ describe.skipIf(!url)('startup migrations on real PostgreSQL', () => {
|
|||
.rows[0].count
|
||||
).toBe(1);
|
||||
});
|
||||
|
||||
test('34-security-master.sql is applied on master and all tracks, excluded from research, and idempotent', async () => {
|
||||
const securityMasterTables = [
|
||||
'exchange',
|
||||
'exchange_source_map',
|
||||
'instrument',
|
||||
'instrument_identifier_history',
|
||||
'listing',
|
||||
'corporate_action_continuity',
|
||||
'listing_symbol_history',
|
||||
'provider_mapping',
|
||||
'resolution_conflict',
|
||||
'override',
|
||||
'golden_field_audit',
|
||||
];
|
||||
|
||||
// 1. research track must NOT apply 34-security-master.sql or create any of its 11 tables;
|
||||
// master track applies it and is idempotent on re-run.
|
||||
const f1 = await fixture();
|
||||
const runner1 = f1.startup();
|
||||
const researchApplied = await runner1.runTrack('research');
|
||||
expect(researchApplied).not.toContain('34-security-master.sql');
|
||||
expect(await f1.recorded()).not.toContain('34-security-master.sql');
|
||||
|
||||
const tablesAfterResearch = new Set(await f1.relations());
|
||||
for (const table of securityMasterTables) {
|
||||
expect(tablesAfterResearch.has(table)).toBe(false);
|
||||
}
|
||||
|
||||
const masterApplied = await runner1.runTrack('master');
|
||||
expect(masterApplied).toContain('34-security-master.sql');
|
||||
expect(await f1.recorded()).toContain('34-security-master.sql');
|
||||
|
||||
const tablesAfterMaster = new Set(await f1.relations());
|
||||
for (const table of securityMasterTables) {
|
||||
expect(tablesAfterMaster.has(table)).toBe(true);
|
||||
}
|
||||
|
||||
expect(await runner1.runTrack('master')).toEqual([]);
|
||||
|
||||
// 2. all track applies 34-security-master.sql alongside 01-05 and 09-33 and is idempotent.
|
||||
const f2 = await fixture();
|
||||
const runner2 = f2.startup();
|
||||
const allApplied = await runner2.runTrack('all');
|
||||
expect(allApplied).toContain('01-init-database.sql');
|
||||
expect(allApplied).toContain('05-add-visible-column.sql');
|
||||
expect(allApplied).toContain('09-backtest-run-contract.sql');
|
||||
expect(allApplied).toContain('33-candidate-decimal-normalization.sql');
|
||||
expect(allApplied).toContain('34-security-master.sql');
|
||||
expect(await f2.recorded()).toContain('34-security-master.sql');
|
||||
|
||||
const tablesAfterAll = new Set(await f2.relations());
|
||||
for (const table of securityMasterTables) {
|
||||
expect(tablesAfterAll.has(table)).toBe(true);
|
||||
}
|
||||
|
||||
expect(await runner2.runTrack('all')).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue