mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 19:16:08 +00:00
refactor(db): define the "TREK's tables" catalog query once
The bootstrap's currentTables and the client tools' pgTableNames each wrote the same information_schema query for the current schema, so a change to which tables count as TREK's would have had to land twice. It is now CURRENT_SCHEMA_TABLES_SQL in dialect/catalog.ts, beside the other catalog statements, and both read it. pgTableNames now lists its names in name order too, as the bootstrap already did. Nothing reads that order for meaning; the boot-restore refusal names the first few tables, and that list was already sorted.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { CURRENT_SCHEMA_TABLES_SQL } from '../../dialect/catalog';
|
||||
import { CLEAR_SCHEMA_SQL } from './clear-schema';
|
||||
import { pgConnectionEnv, run } from './pg-process';
|
||||
import { refuseToolsWithoutRestrict } from './restore-safety';
|
||||
@@ -157,12 +158,7 @@ export async function pgTableNames(url: string, binDir: string | undefined): Pro
|
||||
const out = await run(
|
||||
'psql',
|
||||
binDir,
|
||||
[
|
||||
'--no-psqlrc',
|
||||
'--no-align',
|
||||
'--tuples-only',
|
||||
'--command=select table_name from information_schema.tables where table_schema = current_schema()',
|
||||
],
|
||||
['--no-psqlrc', '--no-align', '--tuples-only', `--command=${CURRENT_SCHEMA_TABLES_SQL}`],
|
||||
pgConnectionEnv(url),
|
||||
);
|
||||
return out.split('\n').filter((line) => line !== '');
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { readEnv, type AppEnv } from '../../../app-config';
|
||||
import { resolveDataPaths } from '../../../app-config/data-paths';
|
||||
import { CURRENT_SCHEMA_TABLES_SQL } from '../../dialect/catalog';
|
||||
import { knownMigrationNames } from '../../known-migrations';
|
||||
import { migrationLabel, REFUSAL, refuseNewerDatabase, type MigrationSafetyNet } from '../../legacy-baseline';
|
||||
import type { AnyOrm } from '../../orm';
|
||||
@@ -32,9 +33,7 @@ export interface PostgresBootstrapDeps {
|
||||
* refused database is left exactly as it was.
|
||||
*/
|
||||
async function currentTables(connection: Connection): Promise<string[]> {
|
||||
const rows: Array<{ table_name: string }> = await connection.execute(
|
||||
'select table_name from information_schema.tables where table_schema = current_schema() order by table_name',
|
||||
);
|
||||
const rows: Array<{ table_name: string }> = await connection.execute(CURRENT_SCHEMA_TABLES_SQL);
|
||||
return rows.map((row) => row.table_name);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user