@danceroutine/tango-migrations 1.6.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{CompilerStrategy-yKw-Egxv.js → CompilerStrategy-_AiXiyjS.js} +9 -2
- package/dist/CompilerStrategy-_AiXiyjS.js.map +1 -0
- package/dist/{IntrospectorStrategy-blvwSU3_.js → IntrospectorStrategy-BEIG5GqA.js} +2 -2
- package/dist/{IntrospectorStrategy-blvwSU3_.js.map → IntrospectorStrategy-BEIG5GqA.js.map} +1 -1
- package/dist/{MigrationRunner-CSt99m9K.js → MigrationRunner-DomrOZIn.js} +6 -4
- package/dist/MigrationRunner-DomrOZIn.js.map +1 -0
- package/dist/{SqliteCompilerFactory-BAodJW9n.js → SqliteCompilerFactory-BvdJ0kBl.js} +121 -2
- package/dist/SqliteCompilerFactory-BvdJ0kBl.js.map +1 -0
- package/dist/{cli-DOBziuSJ.js → cli-7j3R1Y1r.js} +8 -7
- package/dist/cli-7j3R1Y1r.js.map +1 -0
- package/dist/cli.js +6 -6
- package/dist/commands/index.js +7 -7
- package/dist/{commands-DIJepqNg.js → commands-Cl2MU7tq.js} +2 -2
- package/dist/{commands-DIJepqNg.js.map → commands-Cl2MU7tq.js.map} +1 -1
- package/dist/compilers/contracts/SQLCompiler.d.ts +2 -0
- package/dist/compilers/dialects/PostgresCompiler.d.ts +6 -0
- package/dist/compilers/dialects/SqliteCompiler.d.ts +7 -0
- package/dist/compilers/index.js +2 -2
- package/dist/{compilers-dRN0Hzev.js → compilers-C-GiumJB.js} +2 -2
- package/dist/{compilers-dRN0Hzev.js.map → compilers-C-GiumJB.js.map} +1 -1
- package/dist/diff/diffSchema.d.ts +1 -0
- package/dist/diff/index.d.ts +1 -0
- package/dist/diff/index.js +2 -3
- package/dist/{diffSchema-D4oemTWS.js → diff-B9MhagJF.js} +45 -14
- package/dist/diff-B9MhagJF.js.map +1 -0
- package/dist/index.js +10 -11
- package/dist/introspect/index.js +1 -1
- package/dist/{introspect-TPv_jeD6.js → introspect-DD3fm15e.js} +1 -1
- package/dist/{introspect-TPv_jeD6.js.map → introspect-DD3fm15e.js.map} +1 -1
- package/dist/runner/index.js +3 -3
- package/dist/runner-C97xT8_W.js +1 -1
- package/dist/schema/buildMigrationModelMetadataProjection.d.ts +3 -0
- package/dist/strategies/CompilerStrategy.d.ts +4 -0
- package/dist/strategies/index.js +4 -4
- package/dist/{strategies-D9ymSvbG.js → strategies-HwUWvmLC.js} +3 -3
- package/dist/{strategies-D9ymSvbG.js.map → strategies-HwUWvmLC.js.map} +1 -1
- package/package.json +8 -7
- package/dist/CompilerStrategy-yKw-Egxv.js.map +0 -1
- package/dist/MigrationRunner-CSt99m9K.js.map +0 -1
- package/dist/SqliteCompilerFactory-BAodJW9n.js.map +0 -1
- package/dist/cli-DOBziuSJ.js.map +0 -1
- package/dist/diff-CZZbXAPN.js +0 -10
- package/dist/diff-CZZbXAPN.js.map +0 -1
- package/dist/diffSchema-D4oemTWS.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PostgresCompilerFactory, SqliteCompilerFactory } from "./SqliteCompilerFactory-
|
|
1
|
+
import { PostgresCompilerFactory, SqliteCompilerFactory } from "./SqliteCompilerFactory-BvdJ0kBl.js";
|
|
2
2
|
|
|
3
3
|
//#region src/domain/internal/InternalDialect.ts
|
|
4
4
|
const InternalDialect = {
|
|
@@ -23,6 +23,13 @@ var CompilerStrategy = class CompilerStrategy {
|
|
|
23
23
|
return typeof value === "object" && value !== null && value.__tangoBrand === CompilerStrategy.BRAND;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
+
* Prepare a batch of migration operations for a target dialect.
|
|
27
|
+
*/
|
|
28
|
+
prepareOperations(dialect, operations) {
|
|
29
|
+
const compiler = this.getCompiler(dialect);
|
|
30
|
+
return compiler.prepareOperations ? compiler.prepareOperations(operations) : operations;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
26
33
|
* Compile a migration operation to SQL for a target dialect.
|
|
27
34
|
*/
|
|
28
35
|
compile(dialect, operation) {
|
|
@@ -63,4 +70,4 @@ function createDefaultCompilerStrategy() {
|
|
|
63
70
|
|
|
64
71
|
//#endregion
|
|
65
72
|
export { CompilerStrategy, InternalDialect, createDefaultCompilerStrategy };
|
|
66
|
-
//# sourceMappingURL=CompilerStrategy-
|
|
73
|
+
//# sourceMappingURL=CompilerStrategy-_AiXiyjS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompilerStrategy-_AiXiyjS.js","names":["factories: CompilerFactoryRegistry","value: unknown","dialect: Dialect","operations: MigrationOperation[]","operation: MigrationOperation","name: TName","handler: (dialect: Dialect, op: CustomMigrationOperation<TName, TArgs>) => SQL[]"],"sources":["../src/domain/internal/InternalDialect.ts","../src/strategies/CompilerStrategy.ts"],"sourcesContent":["export const InternalDialect = {\n POSTGRES: 'postgres',\n SQLITE: 'sqlite',\n} as const;\n\nexport type InternalDialect = (typeof InternalDialect)[keyof typeof InternalDialect];\n","import { PostgresCompilerFactory } from '../compilers/factories/PostgresCompilerFactory';\nimport { SqliteCompilerFactory } from '../compilers/factories/SqliteCompilerFactory';\nimport type { CompilerFactory } from '../compilers/contracts/CompilerFactory';\nimport type { Dialect } from '../domain/Dialect';\nimport type { CustomMigrationOperation, MigrationOperation } from '../domain/MigrationOperation';\nimport type { SQL } from '../compilers/contracts/SQL';\nimport type { SQLCompiler } from '../compilers/contracts/SQLCompiler';\nimport { InternalDialect } from '../domain/internal/InternalDialect';\n\ntype CompilerFactoryRegistry = Record<Dialect, CompilerFactory>;\n\n/**\n * Dialect-aware SQL compiler orchestration with optional custom-op handlers.\n */\nexport class CompilerStrategy {\n static readonly BRAND = 'tango.migrations.compiler_strategy' as const;\n readonly __tangoBrand: typeof CompilerStrategy.BRAND = CompilerStrategy.BRAND;\n private readonly compilerCache = new Map<Dialect, SQLCompiler>();\n private readonly customHandlers = new Map<string, (dialect: Dialect, op: CustomMigrationOperation) => SQL[]>();\n\n constructor(private readonly factories: CompilerFactoryRegistry) {}\n\n /**\n * Narrow an unknown value to the dialect-aware migration compiler strategy.\n */\n static isCompilerStrategy(value: unknown): value is CompilerStrategy {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === CompilerStrategy.BRAND\n );\n }\n\n /**\n * Prepare a batch of migration operations for a target dialect.\n */\n prepareOperations(dialect: Dialect, operations: MigrationOperation[]): MigrationOperation[] {\n const compiler = this.getCompiler(dialect);\n return compiler.prepareOperations ? compiler.prepareOperations(operations) : operations;\n }\n\n /**\n * Compile a migration operation to SQL for a target dialect.\n */\n compile(dialect: Dialect, operation: MigrationOperation): SQL[] {\n if (operation.kind === 'custom') {\n const handler = this.customHandlers.get(operation.name);\n if (!handler) {\n throw new Error(`Unsupported custom migration op: ${operation.name}`);\n }\n return handler(dialect, operation);\n }\n const compiler = this.getCompiler(dialect);\n return compiler.compile(operation);\n }\n\n /**\n * Register a handler for custom migration operations.\n */\n registerCustomHandler<TName extends string, TArgs extends object>(\n name: TName,\n handler: (dialect: Dialect, op: CustomMigrationOperation<TName, TArgs>) => SQL[]\n ): this {\n this.customHandlers.set(name, handler as (dialect: Dialect, op: CustomMigrationOperation) => SQL[]);\n return this;\n }\n\n /**\n * Resolve and cache a compiler instance for a dialect.\n */\n getCompiler(dialect: Dialect): SQLCompiler {\n const cached = this.compilerCache.get(dialect);\n if (cached) {\n return cached;\n }\n\n const factory = this.factories[dialect];\n if (!factory) {\n throw new Error(`No SQL compiler factory registered for dialect: ${String(dialect)}`);\n }\n const compiler = factory.create();\n this.compilerCache.set(dialect, compiler);\n return compiler;\n }\n}\n\n/**\n * Create the default compiler strategy with built-in dialect factories.\n */\nexport function createDefaultCompilerStrategy(): CompilerStrategy {\n return new CompilerStrategy({\n [InternalDialect.POSTGRES]: new PostgresCompilerFactory(),\n [InternalDialect.SQLITE]: new SqliteCompilerFactory(),\n });\n}\n"],"mappings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
|
1
|
-
import { InternalDialect } from "./CompilerStrategy-
|
|
1
|
+
import { InternalDialect } from "./CompilerStrategy-_AiXiyjS.js";
|
|
2
2
|
import { PostgresIntrospector, SqliteIntrospector } from "./SqliteIntrospector-CWwPWhmA.js";
|
|
3
3
|
|
|
4
4
|
//#region src/strategies/IntrospectorStrategy.ts
|
|
@@ -44,4 +44,4 @@ function createDefaultIntrospectorStrategy() {
|
|
|
44
44
|
|
|
45
45
|
//#endregion
|
|
46
46
|
export { IntrospectorStrategy, createDefaultIntrospectorStrategy };
|
|
47
|
-
//# sourceMappingURL=IntrospectorStrategy-
|
|
47
|
+
//# sourceMappingURL=IntrospectorStrategy-BEIG5GqA.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntrospectorStrategy-
|
|
1
|
+
{"version":3,"file":"IntrospectorStrategy-BEIG5GqA.js","names":["factories: IntrospectorFactoryRegistry","value: unknown","dialect: Dialect","client: DBClient"],"sources":["../src/strategies/IntrospectorStrategy.ts"],"sourcesContent":["import type { DBClient, DatabaseIntrospector } from '../introspect/DatabaseIntrospector';\nimport type { Dialect } from '../domain/Dialect';\nimport { InternalDialect } from '../domain/internal/InternalDialect';\nimport type { DbSchema } from '../introspect/PostgresIntrospector';\nimport { PostgresIntrospector } from '../introspect/PostgresIntrospector';\nimport { SqliteIntrospector } from '../introspect/SqliteIntrospector';\n\ntype IntrospectorFactory = {\n create(): DatabaseIntrospector;\n};\n\ntype IntrospectorFactoryRegistry = Record<Dialect, IntrospectorFactory>;\n\n/**\n * Dialect-aware schema introspection orchestration.\n */\nexport class IntrospectorStrategy {\n static readonly BRAND = 'tango.migrations.introspector_strategy' as const;\n readonly __tangoBrand: typeof IntrospectorStrategy.BRAND = IntrospectorStrategy.BRAND;\n private readonly introspectorCache = new Map<Dialect, DatabaseIntrospector>();\n\n constructor(private readonly factories: IntrospectorFactoryRegistry) {}\n\n /**\n * Narrow an unknown value to the dialect-aware schema introspection strategy.\n */\n static isIntrospectorStrategy(value: unknown): value is IntrospectorStrategy {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === IntrospectorStrategy.BRAND\n );\n }\n\n /**\n * Introspect database schema using a dialect-specific introspector.\n */\n introspect(dialect: Dialect, client: DBClient): Promise<DbSchema> {\n const introspector = this.getIntrospector(dialect);\n return introspector.introspect(client);\n }\n\n /**\n * Resolve and cache an introspector instance for a dialect.\n */\n getIntrospector(dialect: Dialect): DatabaseIntrospector {\n const cached = this.introspectorCache.get(dialect);\n if (cached) {\n return cached;\n }\n\n const factory = this.factories[dialect];\n if (!factory) {\n throw new Error(`No database introspector factory registered for dialect: ${String(dialect)}`);\n }\n\n const introspector = factory.create();\n this.introspectorCache.set(dialect, introspector);\n return introspector;\n }\n}\n\n/**\n * Create the default introspector strategy with built-in dialect support.\n */\nexport function createDefaultIntrospectorStrategy(): IntrospectorStrategy {\n return new IntrospectorStrategy({\n [InternalDialect.POSTGRES]: { create: () => new PostgresIntrospector() },\n [InternalDialect.SQLITE]: { create: () => new SqliteIntrospector() },\n });\n}\n"],"mappings":";;;;IAgBa,uBAAN,MAAM,qBAAqB;CAC9B,OAAgB,QAAQ;CACxB,eAA2D,qBAAqB;CAChF,oBAAqC,IAAI;CAEzC,YAA6BA,WAAwC;AAAA,OAAxC,YAAA;CAA0C;;;;CAKvE,OAAO,uBAAuBC,OAA+C;AACzE,gBACW,UAAU,YACjB,UAAU,QACT,MAAqC,iBAAiB,qBAAqB;CAEnF;;;;CAKD,WAAWC,SAAkBC,QAAqC;EAC9D,MAAM,eAAe,KAAK,gBAAgB,QAAQ;AAClD,SAAO,aAAa,WAAW,OAAO;CACzC;;;;CAKD,gBAAgBD,SAAwC;EACpD,MAAM,SAAS,KAAK,kBAAkB,IAAI,QAAQ;AAClD,MAAI,OACA,QAAO;EAGX,MAAM,UAAU,KAAK,UAAU;AAC/B,OAAK,QACD,OAAM,IAAI,OAAO,2DAA2D,OAAO,QAAQ,CAAC;EAGhG,MAAM,eAAe,QAAQ,QAAQ;AACrC,OAAK,kBAAkB,IAAI,SAAS,aAAa;AACjD,SAAO;CACV;AACJ;AAKM,SAAS,oCAA0D;AACtE,QAAO,IAAI,qBAAqB;GAC3B,gBAAgB,WAAW,EAAE,QAAQ,MAAM,IAAI,uBAAwB;GACvE,gBAAgB,SAAS,EAAE,QAAQ,MAAM,IAAI,qBAAsB;CACvE;AACJ"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CollectingBuilder } from "./CollectingBuilder--4fqDQdE.js";
|
|
2
2
|
import { Migration } from "./Migration-DYQ0hUG7.js";
|
|
3
|
-
import { InternalDialect, createDefaultCompilerStrategy } from "./CompilerStrategy-
|
|
3
|
+
import { InternalDialect, createDefaultCompilerStrategy } from "./CompilerStrategy-_AiXiyjS.js";
|
|
4
4
|
import { readdir } from "node:fs/promises";
|
|
5
5
|
import { extname, resolve, resolve as resolve$1 } from "node:path";
|
|
6
6
|
import { isError } from "@danceroutine/tango-core";
|
|
@@ -86,7 +86,8 @@ var MigrationRunner = class MigrationRunner {
|
|
|
86
86
|
migrations.forEach((migration) => {
|
|
87
87
|
const builder = new CollectingBuilder();
|
|
88
88
|
migration.up(builder);
|
|
89
|
-
const
|
|
89
|
+
const preparedOps = this.compilerStrategy.prepareOperations(this.dialect, builder.ops);
|
|
90
|
+
const sqls = preparedOps.flatMap((op) => this.compileOperation(op));
|
|
90
91
|
output += `# ${migration.id}\n`;
|
|
91
92
|
sqls.forEach((statement) => {
|
|
92
93
|
output += statement.sql + ";\n";
|
|
@@ -151,7 +152,8 @@ var MigrationRunner = class MigrationRunner {
|
|
|
151
152
|
async applyMigration(migration) {
|
|
152
153
|
const builder = new CollectingBuilder();
|
|
153
154
|
await migration.up(builder);
|
|
154
|
-
const
|
|
155
|
+
const preparedOps = this.compilerStrategy.prepareOperations(this.dialect, builder.ops);
|
|
156
|
+
const sqls = preparedOps.flatMap((op) => this.compileOperation(op));
|
|
155
157
|
const checksum = String(this.hashJSON(builder.ops));
|
|
156
158
|
const isOnline = (migration.mode ?? builder.getMode()) === "online";
|
|
157
159
|
if (!isOnline && this.dialect === InternalDialect.POSTGRES) await this.client.query("BEGIN");
|
|
@@ -189,4 +191,4 @@ var MigrationRunner = class MigrationRunner {
|
|
|
189
191
|
|
|
190
192
|
//#endregion
|
|
191
193
|
export { MigrationRunner, loadModule };
|
|
192
|
-
//# sourceMappingURL=MigrationRunner-
|
|
194
|
+
//# sourceMappingURL=MigrationRunner-DomrOZIn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MigrationRunner-DomrOZIn.js","names":["modulePath: string","projectRoot: string","options?: { projectRoot?: string; registry?: ModelRegistry; moduleCache?: boolean }","options?: { projectRoot?: string }","client: DBClient","dialect: Dialect","migrationsDir: string","compilerStrategy?: CompilerStrategy","value: unknown","toId?: string","migrations: Migration[]","loaded: unknown","migration: Migration","x: unknown","op: MigrationOperation"],"sources":["../src/runtime/loadModule.ts","../src/runner/MigrationRunner.ts"],"sourcesContent":["import { resolve, extname } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport { createJiti } from 'jiti';\nimport { ModelRegistry } from '@danceroutine/tango-schema';\n\nconst TS_EXTENSIONS = new Set(['.ts', '.tsx', '.mts', '.cts']);\n\nfunction toAbsolutePath(modulePath: string, projectRoot: string): string {\n return resolve(projectRoot, modulePath);\n}\n\nfunction isTypeScriptModule(modulePath: string): boolean {\n return TS_EXTENSIONS.has(extname(modulePath).toLowerCase());\n}\n\n/**\n * Load a module from a Tango app project root.\n *\n * TypeScript modules are loaded through jiti and JavaScript/ESM modules are loaded\n * through native dynamic import so published installs behave like end-user runtime.\n */\nexport async function loadModule(\n modulePath: string,\n options?: { projectRoot?: string; registry?: ModelRegistry; moduleCache?: boolean }\n): Promise<Record<string, unknown>> {\n const projectRoot = options?.projectRoot ?? process.cwd();\n const absolutePath = toAbsolutePath(modulePath, projectRoot);\n const executeImport = async (): Promise<Record<string, unknown>> => {\n if (isTypeScriptModule(absolutePath)) {\n const jiti = createJiti(resolve(projectRoot, 'tango.config.ts'), {\n interopDefault: true,\n moduleCache: options?.moduleCache ?? true,\n });\n return (await jiti.import<Record<string, unknown>>(absolutePath)) as Record<string, unknown>;\n }\n\n return (await import(pathToFileURL(absolutePath).href)) as Record<string, unknown>;\n };\n\n if (options?.registry) {\n return ModelRegistry.runWithRegistry(options.registry, executeImport);\n }\n\n return executeImport();\n}\n\n/**\n * Load a module and return default export when present.\n */\nexport async function loadDefaultExport(modulePath: string, options?: { projectRoot?: string }): Promise<unknown> {\n const loaded = await loadModule(modulePath, options);\n return loaded.default ?? loaded;\n}\n","import { CollectingBuilder } from '../builder/runtime/CollectingBuilder';\nimport type { Dialect } from '../domain/Dialect';\nimport { Migration } from '../domain/Migration';\nimport type { SQL } from '../compilers/contracts/SQL';\nimport type { MigrationOperation } from '../domain/MigrationOperation';\nimport type { CompilerStrategy } from '../strategies/CompilerStrategy';\nimport { createDefaultCompilerStrategy } from '../strategies/CompilerStrategy';\nimport { InternalDialect } from '../domain/internal/InternalDialect';\nimport { isError } from '@danceroutine/tango-core';\nimport { readdir } from 'node:fs/promises';\nimport { resolve } from 'node:path';\nimport { loadDefaultExport } from '../runtime/loadModule';\n\nconst JOURNAL = '_tango_migrations';\n\n/** DB client contract required by migration execution. */\ninterface DBClient {\n /** Execute SQL with optional parameters. */\n query<T = unknown>(sql: string, params?: readonly unknown[]): Promise<{ rows: T[] }>;\n /** Release underlying database resources. */\n close(): Promise<void>;\n}\n\n/**\n * Manages the lifecycle of database migrations: applying, planning, and tracking status.\n *\n * The runner reads migration files from a directory, compiles operations to SQL\n * for the target dialect, and maintains a journal table to track which migrations\n * have been applied. Each applied migration is checksummed to detect tampering.\n *\n * @example\n * ```typescript\n * const runner = new MigrationRunner(client, 'postgres', './migrations');\n *\n * // Apply all pending migrations\n * await runner.apply();\n *\n * // Apply up to a specific migration\n * await runner.apply('003_add_indexes');\n *\n * // Preview the SQL that would be generated\n * const sql = await runner.plan();\n *\n * // Check which migrations are applied\n * const statuses = await runner.status();\n * ```\n */\nexport class MigrationRunner {\n static readonly BRAND = 'tango.migrations.runner' as const;\n readonly __tangoBrand: typeof MigrationRunner.BRAND = MigrationRunner.BRAND;\n private compilerStrategy: CompilerStrategy;\n\n constructor(\n private client: DBClient,\n private dialect: Dialect,\n private migrationsDir: string = 'migrations',\n compilerStrategy?: CompilerStrategy\n ) {\n this.compilerStrategy = compilerStrategy ?? createDefaultCompilerStrategy();\n }\n\n /**\n * Narrow an unknown value to `MigrationRunner`.\n */\n static isMigrationRunner(value: unknown): value is MigrationRunner {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === MigrationRunner.BRAND\n );\n }\n\n /**\n * Apply all pending migrations, optionally stopping at a specific migration ID.\n * Migrations are applied in file-sort order. Already-applied migrations are skipped.\n * Non-online migrations are wrapped in a transaction on Postgres.\n */\n async apply(toId?: string): Promise<void> {\n await this.ensureJournal();\n const applied = await this.listApplied();\n const migrations = await this.loadMigrations();\n\n for (const migration of migrations) {\n if (toId && migration.id > toId) {\n break;\n }\n if (applied.has(migration.id)) {\n continue;\n }\n\n await this.applyMigration(migration);\n }\n }\n\n /**\n * Generate a dry-run SQL plan for all migrations without executing anything.\n * Useful for reviewing what SQL would be run before applying.\n */\n async plan(): Promise<string> {\n const migrations = await this.loadMigrations();\n let output = '';\n\n migrations.forEach((migration) => {\n const builder = new CollectingBuilder();\n migration.up(builder);\n const preparedOps = this.compilerStrategy.prepareOperations(this.dialect, builder.ops);\n const sqls = preparedOps.flatMap((op) => this.compileOperation(op));\n\n output += `# ${migration.id}\\n`;\n sqls.forEach((statement) => {\n output += statement.sql + ';\\n';\n });\n if (builder.dataFns.length) {\n output += '-- (data step present)\\n';\n }\n output += '\\n';\n });\n\n return output;\n }\n\n /**\n * Return the applied/pending status of every migration found on disk.\n */\n async status(): Promise<{ id: string; applied: boolean }[]> {\n const applied = await this.listApplied();\n const migrations = await this.loadMigrations();\n\n return migrations.map((m) => ({\n id: m.id,\n applied: applied.has(m.id),\n }));\n }\n\n private async ensureJournal(): Promise<void> {\n const sql =\n this.dialect === InternalDialect.POSTGRES\n ? `CREATE TABLE IF NOT EXISTS \"${JOURNAL}\" (\n id TEXT PRIMARY KEY,\n applied_at TIMESTAMPTZ NOT NULL DEFAULT now(),\n checksum TEXT NOT NULL\n )`\n : `CREATE TABLE IF NOT EXISTS ${JOURNAL} (\n id TEXT PRIMARY KEY,\n applied_at TEXT NOT NULL DEFAULT (datetime('now')),\n checksum TEXT NOT NULL\n )`;\n\n await this.client.query(sql);\n }\n\n private async listApplied(): Promise<Set<string>> {\n const table = this.dialect === InternalDialect.POSTGRES ? `\"${JOURNAL}\"` : JOURNAL;\n const { rows } = await this.client.query<{ id: string }>(`SELECT id FROM ${table}`);\n return new Set(rows.map((r) => r.id));\n }\n\n private async loadMigrations(): Promise<Migration[]> {\n const files = (await readdir(this.migrationsDir)).filter((f) => f.endsWith('.ts') || f.endsWith('.js')).sort();\n\n const migrations: Migration[] = [];\n\n for (const file of files) {\n const absolutePath = resolve(this.migrationsDir, file);\n let loaded: unknown;\n try {\n loaded = await loadDefaultExport(absolutePath, { projectRoot: process.cwd() });\n } catch (error) {\n const reason = isError(error) ? error.message : String(error);\n throw new Error(`Failed to load migration module '${file}': ${reason}`, { cause: error });\n }\n\n if (Migration.isMigration(loaded)) {\n migrations.push(loaded);\n continue;\n }\n\n if (Migration.isMigrationConstructor(loaded)) {\n migrations.push(new loaded());\n continue;\n }\n\n throw new Error(\n `Invalid migration module '${file}'. Default export must be a Migration subclass or instance.`\n );\n }\n\n return migrations;\n }\n\n private async applyMigration(migration: Migration): Promise<void> {\n const builder = new CollectingBuilder();\n await migration.up(builder);\n\n const preparedOps = this.compilerStrategy.prepareOperations(this.dialect, builder.ops);\n const sqls = preparedOps.flatMap((op) => this.compileOperation(op));\n const checksum = String(this.hashJSON(builder.ops));\n\n const isOnline = (migration.mode ?? builder.getMode()) === 'online';\n\n if (!isOnline && this.dialect === InternalDialect.POSTGRES) {\n await this.client.query('BEGIN');\n }\n\n try {\n for (const statement of sqls) {\n await this.client.query(statement.sql, statement.params);\n }\n\n for (const fn of builder.dataFns) {\n await fn({ query: (sql, params) => this.client.query(sql, params).then(() => {}) });\n }\n\n const table = this.dialect === InternalDialect.POSTGRES ? `\"${JOURNAL}\"` : JOURNAL;\n const placeholder = this.dialect === InternalDialect.POSTGRES ? '$1, $2' : '?, ?';\n await this.client.query(`INSERT INTO ${table} (id, checksum) VALUES (${placeholder})`, [\n migration.id,\n checksum,\n ]);\n\n if (!isOnline && this.dialect === InternalDialect.POSTGRES) {\n await this.client.query('COMMIT');\n }\n } catch (error) {\n if (!isOnline && this.dialect === InternalDialect.POSTGRES) {\n await this.client.query('ROLLBACK');\n }\n throw error;\n }\n }\n\n /**\n * Compute a simple hash of the migration's operation list.\n * Stored alongside each applied migration in the journal table to detect\n * if a migration file has been modified after it was already applied.\n * Uses a djb2-like hash over the JSON-serialized operations.\n */\n private hashJSON(x: unknown): number {\n const s = JSON.stringify(x);\n let h = 0;\n for (let i = 0; i < s.length; i++) {\n // oxlint-disable-next-line prefer-code-point\n h = Math.imul(31, h) + s.charCodeAt(i);\n // oxlint-disable-next-line prefer-math-trunc\n h = h | 0;\n }\n // oxlint-disable-next-line unicorn/prefer-math-trunc\n return h >>> 0;\n }\n\n private compileOperation(op: MigrationOperation): SQL[] {\n return this.compilerStrategy.compile(this.dialect, op);\n }\n}\n"],"mappings":";;;;;;;;;;;AAKA,MAAM,gBAAgB,IAAI,IAAI;CAAC;CAAO;CAAQ;CAAQ;AAAO;AAE7D,SAAS,eAAeA,YAAoBC,aAA6B;AACrE,QAAO,UAAQ,aAAa,WAAW;AAC1C;AAED,SAAS,mBAAmBD,YAA6B;AACrD,QAAO,cAAc,IAAI,QAAQ,WAAW,CAAC,aAAa,CAAC;AAC9D;AAQM,eAAe,WAClBA,YACAE,SACgC;CAChC,MAAM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gBAAgB,WAAW,WAAW;AAC3E,SAAM,KAAK,OAAO,OAAO,cAAc,MAAM,0BAA0B,YAAY,IAAI,CACnF,UAAU,IACV,QACH,EAAC;AAEF,QAAK,YAAY,KAAK,YAAY,gBAAgB,SAC9C,OAAM,KAAK,OAAO,MAAM,SAAS;EAExC,SAAQ,OAAO;AACZ,QAAK,YAAY,KAAK,YAAY,gBAAgB,SAC9C,OAAM,KAAK,OAAO,MAAM,WAAW;AAEvC,SAAM;EACT;CACJ;;;;;;;CAQD,SAAiBC,GAAoB;EACjC,MAAM,IAAI,KAAK,UAAU,EAAE;EAC3B,IAAI,IAAI;AACR,OAAK,IAAI,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AAE/B,OAAI,KAAK,KAAK,IAAI,EAAE,GAAG,EAAE,WAAW,EAAE;AAEtC,OAAI,IAAI;EACX;AAED,SAAO,MAAM;CAChB;CAED,iBAAyBC,IAA+B;AACpD,SAAO,KAAK,iBAAiB,QAAQ,KAAK,SAAS,GAAG;CACzD;AACJ"}
|
|
@@ -14,6 +14,28 @@ var PostgresCompiler = class PostgresCompiler {
|
|
|
14
14
|
return typeof value === "object" && value !== null && value.__tangoBrand === PostgresCompiler.BRAND;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
+
* Rewrite migration operations into PostgreSQL's preferred execution
|
|
18
|
+
* order, including separating inline foreign keys from table creation.
|
|
19
|
+
*/
|
|
20
|
+
prepareOperations(operations) {
|
|
21
|
+
const tableCreates = [];
|
|
22
|
+
const remainder = [];
|
|
23
|
+
for (const operation of operations) if (operation.kind === InternalOperationKind.TABLE_CREATE) tableCreates.push(operation);
|
|
24
|
+
else remainder.push(operation);
|
|
25
|
+
const strippedCreates = [];
|
|
26
|
+
const foreignKeys = [];
|
|
27
|
+
for (const operation of tableCreates) {
|
|
28
|
+
const { create, fks } = this.stripTableCreateForeignKeys(operation);
|
|
29
|
+
strippedCreates.push(create);
|
|
30
|
+
foreignKeys.push(...fks);
|
|
31
|
+
}
|
|
32
|
+
return [
|
|
33
|
+
...strippedCreates.sort((left, right) => left.table.localeCompare(right.table)),
|
|
34
|
+
...foreignKeys,
|
|
35
|
+
...remainder
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
17
39
|
* Compile a migration operation into one or more PostgreSQL statements.
|
|
18
40
|
*/
|
|
19
41
|
compile(op) {
|
|
@@ -127,6 +149,31 @@ var PostgresCompiler = class PostgresCompiler {
|
|
|
127
149
|
}];
|
|
128
150
|
return [];
|
|
129
151
|
}
|
|
152
|
+
stripTableCreateForeignKeys(op) {
|
|
153
|
+
const fks = [];
|
|
154
|
+
const columns = op.columns.map((column) => {
|
|
155
|
+
if (!column.references) return column;
|
|
156
|
+
const references = column.references;
|
|
157
|
+
fks.push({
|
|
158
|
+
kind: InternalOperationKind.FK_CREATE,
|
|
159
|
+
table: op.table,
|
|
160
|
+
columns: [column.name],
|
|
161
|
+
refTable: references.table,
|
|
162
|
+
refColumns: [references.column],
|
|
163
|
+
onDelete: references.onDelete,
|
|
164
|
+
onUpdate: references.onUpdate
|
|
165
|
+
});
|
|
166
|
+
const { references: _references,...rest } = column;
|
|
167
|
+
return { ...rest };
|
|
168
|
+
});
|
|
169
|
+
return {
|
|
170
|
+
create: {
|
|
171
|
+
...op,
|
|
172
|
+
columns
|
|
173
|
+
},
|
|
174
|
+
fks
|
|
175
|
+
};
|
|
176
|
+
}
|
|
130
177
|
colDDL(column) {
|
|
131
178
|
const parts = [this.sqlSafety.column(column.name)];
|
|
132
179
|
switch (column.type) {
|
|
@@ -211,6 +258,18 @@ var SqliteCompiler = class SqliteCompiler {
|
|
|
211
258
|
return typeof value === "object" && value !== null && value.__tangoBrand === SqliteCompiler.BRAND;
|
|
212
259
|
}
|
|
213
260
|
/**
|
|
261
|
+
* Rewrite migration operations into SQLite's safe execution order,
|
|
262
|
+
* including topological table creation and unique-column add expansion.
|
|
263
|
+
*/
|
|
264
|
+
prepareOperations(operations) {
|
|
265
|
+
const tableCreates = [];
|
|
266
|
+
const remainder = [];
|
|
267
|
+
for (const operation of operations) if (operation.kind === InternalOperationKind.TABLE_CREATE) tableCreates.push(operation);
|
|
268
|
+
else remainder.push(operation);
|
|
269
|
+
const preparedRemainder = remainder.flatMap((operation) => operation.kind === InternalOperationKind.COLUMN_ADD ? this.prepareColumnAdd(operation) : [operation]);
|
|
270
|
+
return [...this.topologicalSortTableCreatesWithReferences(tableCreates), ...preparedRemainder];
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
214
273
|
* Compile a migration operation into one or more SQLite statements.
|
|
215
274
|
*/
|
|
216
275
|
compile(op) {
|
|
@@ -234,7 +293,10 @@ var SqliteCompiler = class SqliteCompiler {
|
|
|
234
293
|
params: []
|
|
235
294
|
}];
|
|
236
295
|
case InternalOperationKind.COLUMN_ADD: return [{
|
|
237
|
-
sql: `ALTER TABLE ${this.sqlSafety.table(op.table)} ADD COLUMN ${this.colDDL(
|
|
296
|
+
sql: `ALTER TABLE ${this.sqlSafety.table(op.table)} ADD COLUMN ${this.colDDL({
|
|
297
|
+
...op.column,
|
|
298
|
+
unique: false
|
|
299
|
+
})}`,
|
|
238
300
|
params: []
|
|
239
301
|
}];
|
|
240
302
|
case InternalOperationKind.COLUMN_DROP: return [{
|
|
@@ -299,6 +361,63 @@ var SqliteCompiler = class SqliteCompiler {
|
|
|
299
361
|
if (column.unique && !column.primaryKey) parts.push("UNIQUE");
|
|
300
362
|
return parts.join(" ");
|
|
301
363
|
}
|
|
364
|
+
prepareColumnAdd(op) {
|
|
365
|
+
const preparedColumn = op.column;
|
|
366
|
+
if (preparedColumn.notNull && preparedColumn.default === undefined && !preparedColumn.primaryKey) throw new Error(`SQLite cannot add NOT NULL column '${preparedColumn.name}' to '${op.table}' without a default or backfill path.`);
|
|
367
|
+
if (!preparedColumn.unique) return [op];
|
|
368
|
+
const addColumn = {
|
|
369
|
+
...op,
|
|
370
|
+
column: {
|
|
371
|
+
...preparedColumn,
|
|
372
|
+
unique: false
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
const createIndex = {
|
|
376
|
+
kind: InternalOperationKind.INDEX_CREATE,
|
|
377
|
+
name: `${op.table}_${preparedColumn.name}_idx`,
|
|
378
|
+
table: op.table,
|
|
379
|
+
on: [preparedColumn.name],
|
|
380
|
+
unique: true
|
|
381
|
+
};
|
|
382
|
+
return [addColumn, createIndex];
|
|
383
|
+
}
|
|
384
|
+
topologicalSortTableCreatesWithReferences(creates) {
|
|
385
|
+
if (creates.length <= 1) return creates;
|
|
386
|
+
const tableSet = new Set(creates.map((create) => create.table));
|
|
387
|
+
const byTable = new Map(creates.map((create) => [create.table, create]));
|
|
388
|
+
const incoming = new Map();
|
|
389
|
+
const dependents = new Map();
|
|
390
|
+
for (const table of tableSet) incoming.set(table, 0);
|
|
391
|
+
for (const create of creates) {
|
|
392
|
+
const seenParents = new Set();
|
|
393
|
+
for (const column of create.columns) {
|
|
394
|
+
if (!column.references) continue;
|
|
395
|
+
const refTable = column.references.table;
|
|
396
|
+
if (refTable === create.table || !tableSet.has(refTable)) continue;
|
|
397
|
+
if (seenParents.has(refTable)) continue;
|
|
398
|
+
seenParents.add(refTable);
|
|
399
|
+
incoming.set(create.table, incoming.get(create.table) + 1);
|
|
400
|
+
if (!dependents.has(refTable)) dependents.set(refTable, new Set());
|
|
401
|
+
dependents.get(refTable).add(create.table);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
const ready = [...tableSet].filter((table) => incoming.get(table) === 0);
|
|
405
|
+
ready.sort((left, right) => left.localeCompare(right));
|
|
406
|
+
const sorted = [];
|
|
407
|
+
while (ready.length) {
|
|
408
|
+
const next = ready.shift();
|
|
409
|
+
sorted.push(byTable.get(next));
|
|
410
|
+
for (const dependent of dependents.get(next) ?? []) {
|
|
411
|
+
incoming.set(dependent, incoming.get(dependent) - 1);
|
|
412
|
+
if (incoming.get(dependent) === 0) {
|
|
413
|
+
ready.push(dependent);
|
|
414
|
+
ready.sort((left, right) => left.localeCompare(right));
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
if (sorted.length !== creates.length) return [...creates].sort((left, right) => left.table.localeCompare(right.table));
|
|
419
|
+
return sorted;
|
|
420
|
+
}
|
|
302
421
|
};
|
|
303
422
|
|
|
304
423
|
//#endregion
|
|
@@ -322,4 +441,4 @@ var SqliteCompilerFactory = class SqliteCompilerFactory {
|
|
|
322
441
|
|
|
323
442
|
//#endregion
|
|
324
443
|
export { PostgresCompiler, PostgresCompilerFactory, SqliteCompiler, SqliteCompilerFactory };
|
|
325
|
-
//# sourceMappingURL=SqliteCompilerFactory-
|
|
444
|
+
//# sourceMappingURL=SqliteCompilerFactory-BvdJ0kBl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqliteCompilerFactory-BvdJ0kBl.js","names":["value: unknown","operations: MigrationOperation[]","tableCreates: TableCreate[]","remainder: MigrationOperation[]","strippedCreates: TableCreate[]","foreignKeys: ForeignKeyCreate[]","op: MigrationOperation","constraints: string[]","out: SQL[]","table: string","column: string","defaultValue: unknown","op: TableCreate","fks: ForeignKeyCreate[]","column: ColumnSpec","parts: string[]","type: ColumnType","exhaustive: never","value: unknown","value: unknown","operations: MigrationOperation[]","tableCreates: TableCreate[]","remainder: MigrationOperation[]","op: MigrationOperation","column: ColumnSpec","parts: string[]","op: ColumnAdd","addColumn: ColumnAdd","createIndex: IndexCreate","creates: TableCreate[]","sorted: TableCreate[]","value: unknown"],"sources":["../src/compilers/dialects/PostgresCompiler.ts","../src/compilers/factories/PostgresCompilerFactory.ts","../src/compilers/dialects/SqliteCompiler.ts","../src/compilers/factories/SqliteCompilerFactory.ts"],"sourcesContent":["import type { ForeignKeyCreate, MigrationOperation, TableCreate } from '../../domain/MigrationOperation';\nimport type { SQL } from '../contracts/SQL';\nimport type { ColumnSpec } from '../../builder/contracts/ColumnSpec';\nimport type { ColumnType } from '../../builder/contracts/ColumnType';\nimport type { SQLCompiler } from '../contracts/SQLCompiler';\nimport { InternalOperationKind } from '../../domain/internal/InternalOperationKind';\nimport { InternalColumnType } from '../../domain/internal/InternalColumnType';\nimport { MigrationSqlSafetyAdapter } from '../../internal/MigrationSqlSafetyAdapter';\n\n/**\n * PostgreSQL SQL compiler for migration operations.\n */\nexport class PostgresCompiler implements SQLCompiler {\n static readonly BRAND = 'tango.migrations.postgres_compiler' as const;\n readonly __tangoBrand: typeof PostgresCompiler.BRAND = PostgresCompiler.BRAND;\n private readonly sqlSafety = new MigrationSqlSafetyAdapter('postgres');\n\n /**\n * Narrow an unknown value to the PostgreSQL migration compiler implementation.\n */\n static isPostgresCompiler(value: unknown): value is PostgresCompiler {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === PostgresCompiler.BRAND\n );\n }\n\n /**\n * Rewrite migration operations into PostgreSQL's preferred execution\n * order, including separating inline foreign keys from table creation.\n */\n prepareOperations(operations: MigrationOperation[]): MigrationOperation[] {\n const tableCreates: TableCreate[] = [];\n const remainder: MigrationOperation[] = [];\n\n for (const operation of operations) {\n if (operation.kind === InternalOperationKind.TABLE_CREATE) {\n tableCreates.push(operation);\n } else {\n remainder.push(operation);\n }\n }\n\n const strippedCreates: TableCreate[] = [];\n const foreignKeys: ForeignKeyCreate[] = [];\n\n for (const operation of tableCreates) {\n const { create, fks } = this.stripTableCreateForeignKeys(operation);\n strippedCreates.push(create);\n foreignKeys.push(...fks);\n }\n\n return [\n ...strippedCreates.sort((left, right) => left.table.localeCompare(right.table)),\n ...foreignKeys,\n ...remainder,\n ];\n }\n\n /**\n * Compile a migration operation into one or more PostgreSQL statements.\n */\n compile(op: MigrationOperation): SQL[] {\n switch (op.kind) {\n case InternalOperationKind.TABLE_CREATE: {\n const cols = op.columns.map((c) => this.colDDL(c)).join(', ');\n const pkCols = op.columns.filter((c) => c.primaryKey).map((c) => this.sqlSafety.column(c.name));\n const constraints: string[] = [];\n\n if (pkCols.length) {\n constraints.push(`PRIMARY KEY (${pkCols.join(', ')})`);\n }\n\n op.columns\n .filter((column) => column.references)\n .forEach((column) => {\n const references = column.references!;\n const fkName = `${op.table}_${column.name}_fkey`;\n let fk = `CONSTRAINT ${this.sqlSafety.constraint(fkName)} FOREIGN KEY (${this.sqlSafety.column(column.name)}) REFERENCES ${this.sqlSafety.table(references.table)}(${this.sqlSafety.column(references.column)})`;\n if (references.onDelete) {\n fk += ` ON DELETE ${references.onDelete}`;\n }\n if (references.onUpdate) {\n fk += ` ON UPDATE ${references.onUpdate}`;\n }\n constraints.push(fk);\n });\n\n const allParts = [cols, ...constraints].join(', ');\n const sql = `CREATE TABLE ${this.sqlSafety.table(op.table)} (${allParts})`;\n return [{ sql, params: [] }];\n }\n\n case InternalOperationKind.TABLE_DROP:\n return [\n { sql: `DROP TABLE ${this.sqlSafety.table(op.table)}${op.cascade ? ' CASCADE' : ''}`, params: [] },\n ];\n\n case InternalOperationKind.COLUMN_ADD:\n return [\n {\n sql: `ALTER TABLE ${this.sqlSafety.table(op.table)} ADD COLUMN ${this.colDDL(op.column)}`,\n params: [],\n },\n ];\n\n case InternalOperationKind.COLUMN_DROP:\n return [\n {\n sql: `ALTER TABLE ${this.sqlSafety.table(op.table)} DROP COLUMN ${this.sqlSafety.column(op.column)}`,\n params: [],\n },\n ];\n\n case InternalOperationKind.COLUMN_ALTER: {\n const out: SQL[] = [];\n if (op.to.type) {\n out.push({\n sql: `ALTER TABLE ${this.sqlSafety.table(op.table)} ALTER COLUMN ${this.sqlSafety.column(op.column)} TYPE ${this.typeToSQL(op.to.type)}`,\n params: [],\n });\n }\n if (op.to.notNull !== undefined) {\n out.push({\n sql: `ALTER TABLE ${this.sqlSafety.table(op.table)} ALTER COLUMN ${this.sqlSafety.column(op.column)} ${op.to.notNull ? 'SET NOT NULL' : 'DROP NOT NULL'}`,\n params: [],\n });\n }\n out.push(...this.compileDefaultChange(op.table, op.column, op.to.default));\n return out;\n }\n\n case InternalOperationKind.COLUMN_RENAME:\n return [\n {\n sql: `ALTER TABLE ${this.sqlSafety.table(op.table)} RENAME COLUMN ${this.sqlSafety.column(op.from)} TO ${this.sqlSafety.column(op.to)}`,\n params: [],\n },\n ];\n\n case InternalOperationKind.INDEX_CREATE: {\n const cols = this.sqlSafety.columns(op.on).join(', ');\n const uniq = op.unique ? 'UNIQUE ' : '';\n const conc = op.concurrently ? 'CONCURRENTLY ' : '';\n const where = this.sqlSafety.optionalRawFragment('where', op.where);\n return [\n {\n sql: `CREATE ${uniq}INDEX ${conc}${this.sqlSafety.index(op.name)} ON ${this.sqlSafety.table(op.table)} (${cols})${where ? ` WHERE ${where}` : ''}`,\n params: [],\n },\n ];\n }\n\n case InternalOperationKind.INDEX_DROP: {\n const conc = op.concurrently ? 'CONCURRENTLY ' : '';\n return [{ sql: `DROP INDEX ${conc}${this.sqlSafety.index(op.name)}`, params: [] }];\n }\n\n case InternalOperationKind.FK_CREATE: {\n const cols = this.sqlSafety.columns(op.columns).join(', ');\n const refs = this.sqlSafety.columns(op.refColumns).join(', ');\n const name = op.name ?? `${op.table}_${op.columns.join('_')}_fkey`;\n const notValid = op.notValid ? ' NOT VALID' : '';\n const onDel = op.onDelete ? ` ON DELETE ${op.onDelete}` : '';\n const onUpd = op.onUpdate ? ` ON UPDATE ${op.onUpdate}` : '';\n return [\n {\n sql: `ALTER TABLE ${this.sqlSafety.table(op.table)} ADD CONSTRAINT ${this.sqlSafety.constraint(name)} FOREIGN KEY (${cols}) REFERENCES ${this.sqlSafety.table(op.refTable)} (${refs})${onDel}${onUpd}${notValid}`,\n params: [],\n },\n ];\n }\n\n case InternalOperationKind.FK_VALIDATE:\n return [\n {\n sql: `ALTER TABLE ${this.sqlSafety.table(op.table)} VALIDATE CONSTRAINT ${this.sqlSafety.constraint(op.name)}`,\n params: [],\n },\n ];\n\n case InternalOperationKind.FK_DROP:\n return [\n {\n sql: `ALTER TABLE ${this.sqlSafety.table(op.table)} DROP CONSTRAINT ${this.sqlSafety.constraint(op.name)}`,\n params: [],\n },\n ];\n\n default:\n return [];\n }\n }\n\n /**\n * Compile a DEFAULT value change into ALTER TABLE statements.\n * Extracted to flatten the nested conditional logic.\n */\n private compileDefaultChange(table: string, column: string, defaultValue: unknown): SQL[] {\n if (defaultValue === undefined) {\n return [];\n }\n\n if (defaultValue === null) {\n return [\n {\n sql: `ALTER TABLE ${this.sqlSafety.table(table)} ALTER COLUMN ${this.sqlSafety.column(column)} DROP DEFAULT`,\n params: [],\n },\n ];\n }\n\n if (this.sqlSafety.isTrustedFragment(defaultValue)) {\n return [\n {\n sql: `ALTER TABLE ${this.sqlSafety.table(table)} ALTER COLUMN ${this.sqlSafety.column(column)} SET DEFAULT ${this.sqlSafety.rawFragment('default', defaultValue)}`,\n params: [],\n },\n ];\n }\n\n if (\n defaultValue &&\n typeof defaultValue === 'object' &&\n 'now' in defaultValue &&\n (defaultValue as { now?: unknown }).now\n ) {\n return [\n {\n sql: `ALTER TABLE ${this.sqlSafety.table(table)} ALTER COLUMN ${this.sqlSafety.column(column)} SET DEFAULT now()`,\n params: [],\n },\n ];\n }\n\n return [];\n }\n\n private stripTableCreateForeignKeys(op: TableCreate): { create: TableCreate; fks: ForeignKeyCreate[] } {\n const fks: ForeignKeyCreate[] = [];\n const columns = op.columns.map((column) => {\n if (!column.references) {\n return column;\n }\n\n const references = column.references;\n fks.push({\n kind: InternalOperationKind.FK_CREATE,\n table: op.table,\n columns: [column.name],\n refTable: references.table,\n refColumns: [references.column],\n onDelete: references.onDelete,\n onUpdate: references.onUpdate,\n });\n\n const { references: _references, ...rest } = column;\n return { ...rest };\n });\n\n return { create: { ...op, columns }, fks };\n }\n\n private colDDL(column: ColumnSpec): string {\n const parts: string[] = [this.sqlSafety.column(column.name)];\n\n switch (column.type) {\n case InternalColumnType.SERIAL:\n parts.push('SERIAL');\n break;\n case InternalColumnType.INT:\n parts.push('INTEGER');\n break;\n case InternalColumnType.BIGINT:\n parts.push('BIGINT');\n break;\n case InternalColumnType.TEXT:\n parts.push('TEXT');\n break;\n case InternalColumnType.BOOL:\n parts.push('BOOLEAN');\n break;\n case InternalColumnType.TIMESTAMPTZ:\n parts.push('TIMESTAMPTZ');\n break;\n case InternalColumnType.JSONB:\n parts.push('JSONB');\n break;\n case InternalColumnType.UUID:\n parts.push('UUID');\n break;\n }\n\n if (column.notNull) {\n parts.push('NOT NULL');\n }\n const defaultSql = this.sqlSafety.rawDefault(column.default, 'now()');\n if (defaultSql) {\n parts.push(`DEFAULT ${defaultSql}`);\n }\n if (column.unique && !column.primaryKey) {\n parts.push('UNIQUE');\n }\n\n return parts.join(' ');\n }\n\n private typeToSQL(type: ColumnType): string {\n switch (type) {\n case InternalColumnType.SERIAL:\n return 'SERIAL';\n case InternalColumnType.INT:\n return 'INTEGER';\n case InternalColumnType.BIGINT:\n return 'BIGINT';\n case InternalColumnType.TEXT:\n return 'TEXT';\n case InternalColumnType.BOOL:\n return 'BOOLEAN';\n case InternalColumnType.TIMESTAMPTZ:\n return 'TIMESTAMPTZ';\n case InternalColumnType.JSONB:\n return 'JSONB';\n case InternalColumnType.UUID:\n return 'UUID';\n default: {\n const exhaustive: never = type;\n throw new Error(`Unsupported column type: ${exhaustive}`);\n }\n }\n }\n}\n","import type { CompilerFactory } from '../contracts/CompilerFactory';\nimport type { SQLCompiler } from '../contracts/SQLCompiler';\nimport { PostgresCompiler } from '../dialects/PostgresCompiler';\n\n/**\n * Factory for PostgreSQL migration compilers.\n */\nexport class PostgresCompilerFactory implements CompilerFactory {\n static readonly BRAND = 'tango.migrations.postgres_compiler_factory' as const;\n readonly __tangoBrand: typeof PostgresCompilerFactory.BRAND = PostgresCompilerFactory.BRAND;\n\n /**\n * Narrow an unknown value to the factory that provisions PostgreSQL compilers.\n */\n static isPostgresCompilerFactory(value: unknown): value is PostgresCompilerFactory {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === PostgresCompilerFactory.BRAND\n );\n }\n\n /**\n * Create a PostgreSQL SQL compiler instance.\n */\n create(): SQLCompiler {\n return new PostgresCompiler();\n }\n}\n","import type { ColumnAdd, IndexCreate, MigrationOperation, TableCreate } from '../../domain/MigrationOperation';\nimport type { SQL } from '../contracts/SQL';\nimport type { ColumnSpec } from '../../builder/contracts/ColumnSpec';\nimport type { SQLCompiler } from '../contracts/SQLCompiler';\nimport { InternalOperationKind } from '../../domain/internal/InternalOperationKind';\nimport { InternalColumnType } from '../../domain/internal/InternalColumnType';\nimport { MigrationSqlSafetyAdapter } from '../../internal/MigrationSqlSafetyAdapter';\n\n/**\n * SQLite SQL compiler for migration operations.\n */\nexport class SqliteCompiler implements SQLCompiler {\n static readonly BRAND = 'tango.migrations.sqlite_compiler' as const;\n readonly __tangoBrand: typeof SqliteCompiler.BRAND = SqliteCompiler.BRAND;\n private readonly sqlSafety = new MigrationSqlSafetyAdapter('sqlite');\n\n /**\n * Narrow an unknown value to the SQLite migration compiler implementation.\n */\n static isSqliteCompiler(value: unknown): value is SqliteCompiler {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === SqliteCompiler.BRAND\n );\n }\n\n /**\n * Rewrite migration operations into SQLite's safe execution order,\n * including topological table creation and unique-column add expansion.\n */\n prepareOperations(operations: MigrationOperation[]): MigrationOperation[] {\n const tableCreates: TableCreate[] = [];\n const remainder: MigrationOperation[] = [];\n\n for (const operation of operations) {\n if (operation.kind === InternalOperationKind.TABLE_CREATE) {\n tableCreates.push(operation);\n } else {\n remainder.push(operation);\n }\n }\n\n const preparedRemainder = remainder.flatMap((operation) =>\n operation.kind === InternalOperationKind.COLUMN_ADD ? this.prepareColumnAdd(operation) : [operation]\n );\n\n return [...this.topologicalSortTableCreatesWithReferences(tableCreates), ...preparedRemainder];\n }\n\n /**\n * Compile a migration operation into one or more SQLite statements.\n */\n compile(op: MigrationOperation): SQL[] {\n switch (op.kind) {\n case InternalOperationKind.TABLE_CREATE: {\n const cols = op.columns.map((c) => this.colDDL(c));\n const pkCols = op.columns\n .filter((c) => c.primaryKey && c.type !== InternalColumnType.SERIAL)\n .map((c) => this.sqlSafety.column(c.name));\n\n if (pkCols.length) {\n cols.push(`PRIMARY KEY (${pkCols.join(', ')})`);\n }\n\n op.columns\n .filter((column) => column.references)\n .forEach((column) => {\n const references = column.references!;\n cols.push(\n `FOREIGN KEY (${this.sqlSafety.column(column.name)}) REFERENCES ${this.sqlSafety.table(references.table)}(${this.sqlSafety.column(references.column)})${references.onDelete ? ` ON DELETE ${references.onDelete}` : ''}${references.onUpdate ? ` ON UPDATE ${references.onUpdate}` : ''}`\n );\n });\n\n const sql = `CREATE TABLE ${this.sqlSafety.table(op.table)} (${cols.join(', ')})`;\n return [{ sql, params: [] }];\n }\n\n case InternalOperationKind.TABLE_DROP:\n return [{ sql: `DROP TABLE ${this.sqlSafety.table(op.table)}`, params: [] }];\n\n case InternalOperationKind.COLUMN_ADD:\n return [\n {\n sql: `ALTER TABLE ${this.sqlSafety.table(op.table)} ADD COLUMN ${this.colDDL({\n ...op.column,\n unique: false,\n })}`,\n params: [],\n },\n ];\n\n case InternalOperationKind.COLUMN_DROP:\n return [\n {\n sql: `ALTER TABLE ${this.sqlSafety.table(op.table)} DROP COLUMN ${this.sqlSafety.column(op.column)}`,\n params: [],\n },\n ];\n\n case InternalOperationKind.COLUMN_RENAME:\n return [\n {\n sql: `ALTER TABLE ${this.sqlSafety.table(op.table)} RENAME COLUMN ${this.sqlSafety.column(op.from)} TO ${this.sqlSafety.column(op.to)}`,\n params: [],\n },\n ];\n\n case InternalOperationKind.INDEX_CREATE: {\n const cols = this.sqlSafety.columns(op.on).join(', ');\n const uniq = op.unique ? 'UNIQUE ' : '';\n const where = this.sqlSafety.optionalRawFragment('where', op.where);\n return [\n {\n sql: `CREATE ${uniq}INDEX ${this.sqlSafety.index(op.name)} ON ${this.sqlSafety.table(op.table)} (${cols})${where ? ` WHERE ${where}` : ''}`,\n params: [],\n },\n ];\n }\n\n case InternalOperationKind.INDEX_DROP:\n return [{ sql: `DROP INDEX ${this.sqlSafety.index(op.name)}`, params: [] }];\n\n case InternalOperationKind.COLUMN_ALTER:\n case InternalOperationKind.FK_CREATE:\n case InternalOperationKind.FK_VALIDATE:\n case InternalOperationKind.FK_DROP:\n return [];\n\n default:\n return [];\n }\n }\n\n private colDDL(column: ColumnSpec): string {\n const parts: string[] = [this.sqlSafety.column(column.name)];\n\n switch (column.type) {\n case InternalColumnType.SERIAL:\n parts.push('INTEGER PRIMARY KEY AUTOINCREMENT');\n return parts.join(' ');\n case InternalColumnType.INT:\n parts.push('INTEGER');\n break;\n case InternalColumnType.BIGINT:\n parts.push('INTEGER');\n break;\n case InternalColumnType.TEXT:\n parts.push('TEXT');\n break;\n case InternalColumnType.BOOL:\n parts.push('INTEGER');\n break;\n case InternalColumnType.TIMESTAMPTZ:\n parts.push('TEXT');\n break;\n case InternalColumnType.JSONB:\n parts.push('TEXT');\n break;\n case InternalColumnType.UUID:\n parts.push('TEXT');\n break;\n }\n\n if (column.notNull) {\n parts.push('NOT NULL');\n }\n const defaultSql = this.sqlSafety.rawDefault(column.default, \"(datetime('now'))\");\n if (defaultSql) {\n parts.push(`DEFAULT ${defaultSql}`);\n }\n if (column.unique && !column.primaryKey) {\n parts.push('UNIQUE');\n }\n\n return parts.join(' ');\n }\n\n private prepareColumnAdd(op: ColumnAdd): MigrationOperation[] {\n const preparedColumn = op.column;\n if (preparedColumn.notNull && preparedColumn.default === undefined && !preparedColumn.primaryKey) {\n throw new Error(\n `SQLite cannot add NOT NULL column '${preparedColumn.name}' to '${op.table}' without a default or backfill path.`\n );\n }\n\n if (!preparedColumn.unique) {\n return [op];\n }\n\n const addColumn: ColumnAdd = {\n ...op,\n column: {\n ...preparedColumn,\n unique: false,\n },\n };\n const createIndex: IndexCreate = {\n kind: InternalOperationKind.INDEX_CREATE,\n name: `${op.table}_${preparedColumn.name}_idx`,\n table: op.table,\n on: [preparedColumn.name],\n unique: true,\n };\n\n return [addColumn, createIndex];\n }\n\n private topologicalSortTableCreatesWithReferences(creates: TableCreate[]): TableCreate[] {\n if (creates.length <= 1) {\n return creates;\n }\n\n const tableSet = new Set(creates.map((create) => create.table));\n const byTable = new Map(creates.map((create) => [create.table, create]));\n const incoming = new Map<string, number>();\n const dependents = new Map<string, Set<string>>();\n\n for (const table of tableSet) {\n incoming.set(table, 0);\n }\n\n for (const create of creates) {\n const seenParents = new Set<string>();\n for (const column of create.columns) {\n if (!column.references) {\n continue;\n }\n const refTable = column.references.table;\n if (refTable === create.table || !tableSet.has(refTable)) {\n continue;\n }\n if (seenParents.has(refTable)) {\n continue;\n }\n seenParents.add(refTable);\n incoming.set(create.table, incoming.get(create.table)! + 1);\n if (!dependents.has(refTable)) {\n dependents.set(refTable, new Set());\n }\n dependents.get(refTable)!.add(create.table);\n }\n }\n\n const ready = [...tableSet].filter((table) => incoming.get(table) === 0);\n ready.sort((left, right) => left.localeCompare(right));\n\n const sorted: TableCreate[] = [];\n while (ready.length) {\n const next = ready.shift()!;\n sorted.push(byTable.get(next)!);\n\n for (const dependent of dependents.get(next) ?? []) {\n incoming.set(dependent, incoming.get(dependent)! - 1);\n if (incoming.get(dependent) === 0) {\n ready.push(dependent);\n ready.sort((left, right) => left.localeCompare(right));\n }\n }\n }\n\n if (sorted.length !== creates.length) {\n return [...creates].sort((left, right) => left.table.localeCompare(right.table));\n }\n\n return sorted;\n }\n}\n","import type { CompilerFactory } from '../contracts/CompilerFactory';\nimport type { SQLCompiler } from '../contracts/SQLCompiler';\nimport { SqliteCompiler } from '../dialects/SqliteCompiler';\n\n/**\n * Factory for SQLite migration compilers.\n */\nexport class SqliteCompilerFactory implements CompilerFactory {\n static readonly BRAND = 'tango.migrations.sqlite_compiler_factory' as const;\n readonly __tangoBrand: typeof SqliteCompilerFactory.BRAND = SqliteCompilerFactory.BRAND;\n\n /**\n * Narrow an unknown value to the factory that provisions SQLite compilers.\n */\n static isSqliteCompilerFactory(value: unknown): value is SqliteCompilerFactory {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === SqliteCompilerFactory.BRAND\n );\n }\n\n /**\n * Create a SQLite SQL compiler instance.\n */\n create(): SQLCompiler {\n return new SqliteCompiler();\n }\n}\n"],"mappings":";;;;;IAYa,mBAAN,MAAM,iBAAwC;CACjD,OAAgB,QAAQ;CACxB,eAAuD,iBAAiB;CACxE,YAA6B,IAAI,0BAA0B;;;;CAK3D,OAAO,mBAAmBA,OAA2C;AACjE,gBACW,UAAU,YACjB,UAAU,QACT,MAAqC,iBAAiB,iBAAiB;CAE/E;;;;;CAMD,kBAAkBC,YAAwD;EACtE,MAAMC,eAA8B,CAAE;EACtC,MAAMC,YAAkC,CAAE;AAE1C,OAAK,MAAM,aAAa,WACpB,KAAI,UAAU,SAAS,sBAAsB,aACzC,cAAa,KAAK,UAAU;IAE5B,WAAU,KAAK,UAAU;EAIjC,MAAMC,kBAAiC,CAAE;EACzC,MAAMC,cAAkC,CAAE;AAE1C,OAAK,MAAM,aAAa,cAAc;GAClC,MAAM,EAAE,QAAQ,KAAK,GAAG,KAAK,4BAA4B,UAAU;AACnE,mBAAgB,KAAK,OAAO;AAC5B,eAAY,KAAK,GAAG,IAAI;EAC3B;AAED,SAAO;GACH,GAAG,gBAAgB,KAAK,CAAC,MAAM,UAAU,KAAK,MAAM,cAAc,MAAM,MAAM,CAAC;GAC/E,GAAG;GACH,GAAG;EACN;CACJ;;;;CAKD,QAAQC,IAA+B;AACnC,UAAQ,GAAG,MAAX;AACI,QAAK,sBAAsB,cAAc;IACrC,MAAM,OAAO,GAAG,QAAQ,IAAI,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC,CAAC,KAAK,KAAK;IAC7D,MAAM,SAAS,GAAG,QAAQ,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,MAAM,KAAK,UAAU,OAAO,EAAE,KAAK,CAAC;IAC/F,MAAMC,cAAwB,CAAE;AAEhC,QAAI,OAAO,OACP,aAAY,MAAM,eAAe,OAAO,KAAK,KA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U,KAAK,cAAc,MAAM,CAAC;EAEtD,MAAMC,SAAwB,CAAE;AAChC,SAAO,MAAM,QAAQ;GACjB,MAAM,OAAO,MAAM,OAAO;AAC1B,UAAO,KAAK,QAAQ,IAAI,KAAK,CAAE;AAE/B,QAAK,MAAM,aAAa,WAAW,IAAI,KAAK,IAAI,CAAE,GAAE;AAChD,aAAS,IAAI,WAAW,SAAS,IAAI,UAAU,GAAI,EAAE;AACrD,QAAI,SAAS,IAAI,UAAU,KAAK,GAAG;AAC/B,WAAM,KAAK,UAAU;AACrB,WAAM,KAAK,CAAC,MAAM,UAAU,KAAK,cAAc,MAAM,CAAC;IACzD;GACJ;EACJ;AAED,MAAI,OAAO,WAAW,QAAQ,OAC1B,QAAO,CAAC,GAAG,OAAQ,EAAC,KAAK,CAAC,MAAM,UAAU,KAAK,MAAM,cAAc,MAAM,MAAM,CAAC;AAGpF,SAAO;CACV;AACJ;;;;ICpQY,wBAAN,MAAM,sBAAiD;CAC1D,OAAgB,QAAQ;CACxB,eAA4D,sBAAsB;;;;CAKlF,OAAO,wBAAwBC,OAAgD;AAC3E,gBACW,UAAU,YACjB,UAAU,QACT,MAAqC,iBAAiB,sBAAsB;CAEpF;;;;CAKD,SAAsB;AAClB,SAAO,IAAI;CACd;AACJ"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { InternalDialect } from "./CompilerStrategy-
|
|
2
|
-
import { MigrationRunner, loadModule } from "./MigrationRunner-
|
|
1
|
+
import { InternalDialect } from "./CompilerStrategy-_AiXiyjS.js";
|
|
2
|
+
import { MigrationRunner, loadModule } from "./MigrationRunner-DomrOZIn.js";
|
|
3
3
|
import { MigrationGenerator } from "./MigrationGenerator-B1p0jHnx.js";
|
|
4
|
-
import { diffSchema } from "./
|
|
5
|
-
import { createDefaultIntrospectorStrategy } from "./IntrospectorStrategy-
|
|
4
|
+
import { buildMigrationModelMetadataProjection, diffSchema } from "./diff-B9MhagJF.js";
|
|
5
|
+
import { createDefaultIntrospectorStrategy } from "./IntrospectorStrategy-BEIG5GqA.js";
|
|
6
6
|
import { access, mkdir } from "node:fs/promises";
|
|
7
7
|
import { constants as fsConstants } from "node:fs";
|
|
8
8
|
import { dirname, resolve } from "node:path";
|
|
@@ -232,7 +232,8 @@ function registerMigrationsCommands(yargsBuilder) {
|
|
|
232
232
|
env: argv.env
|
|
233
233
|
});
|
|
234
234
|
const loaded = await loadModels(argv.models);
|
|
235
|
-
|
|
235
|
+
const projectedModels = buildMigrationModelMetadataProjection(loaded.registry);
|
|
236
|
+
logger.info(`Found ${loaded.models.length} exported model(s); ${projectedModels.length} model(s) after projection: ${projectedModels.map((m) => m.table).join(", ")}`);
|
|
236
237
|
try {
|
|
237
238
|
await writeRelationRegistryArtifacts({
|
|
238
239
|
registry: loaded.registry,
|
|
@@ -247,7 +248,7 @@ function registerMigrationsCommands(yargsBuilder) {
|
|
|
247
248
|
logger.info("Introspecting database...");
|
|
248
249
|
dbState = await connectAndIntrospect(resolved.db, resolved.dialect);
|
|
249
250
|
} else dbState = { tables: {} };
|
|
250
|
-
const operations = diffSchema(dbState,
|
|
251
|
+
const operations = diffSchema(dbState, projectedModels);
|
|
251
252
|
if (operations.length === 0) {
|
|
252
253
|
logger.info("No changes detected — models and database are in sync");
|
|
253
254
|
return;
|
|
@@ -336,4 +337,4 @@ else statuses.forEach((statusItem) => {
|
|
|
336
337
|
|
|
337
338
|
//#endregion
|
|
338
339
|
export { registerMigrationsCommands };
|
|
339
|
-
//# sourceMappingURL=cli-
|
|
340
|
+
//# sourceMappingURL=cli-7j3R1Y1r.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-7j3R1Y1r.js","names":["modulePath: string","configPathArg: string | undefined","configEnvArg: ConfigEnvironment | undefined","db: {\n adapter: string;\n url?: string;\n filename?: string;\n host?: string;\n port?: number;\n database?: string;\n user?: string;\n password?: string;\n}","argv: {\n dialect?: string;\n dir?: string;\n db?: string;\n config?: string;\n env?: ConfigEnvironment;\n}","value: unknown","moduleValue: unknown","models: ModelMetadataLike[]","modelsPath: string","dbUrl: string","dialect: string","db: string","dialect: Dialect","sql: string","params?: readonly unknown[]","filename: string","yargsBuilder: Argv","dbState: DbSchema"],"sources":["../src/commands/cli.ts"],"sourcesContent":["import { access, mkdir } from 'node:fs/promises';\nimport { constants as fsConstants } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport type { Argv } from 'yargs';\nimport { MigrationRunner } from '../runner/MigrationRunner';\nimport { MigrationGenerator } from '../generator/MigrationGenerator';\nimport { buildMigrationModelMetadataProjection, diffSchema } from '../diff/index';\nimport type { DbSchema } from '../introspect/PostgresIntrospector';\nimport type { Dialect } from '../domain/Dialect';\nimport type { ColumnType } from '../builder/contracts/ColumnType';\nimport type { DeleteReferentialAction } from '../builder/contracts/DeleteReferentialAction';\nimport type { UpdateReferentialAction } from '../builder/contracts/UpdateReferentialAction';\nimport { createDefaultIntrospectorStrategy } from '../strategies/IntrospectorStrategy';\nimport { InternalDialect } from '../domain/internal/InternalDialect';\nimport { loadConfig } from '@danceroutine/tango-config';\nimport { loadProjectModule } from '@danceroutine/tango-codegen/commands';\nimport { writeRelationRegistryArtifacts } from '@danceroutine/tango-codegen/generators';\nimport { getLogger } from '@danceroutine/tango-core';\nimport { GENERATED_RELATION_REGISTRY_DIRNAME, ModelRegistry } from '@danceroutine/tango-schema';\nimport { loadModule } from '../runtime/loadModule';\n\nconst logger = getLogger('tango.migrations');\n\ntype ConfigEnvironment = 'development' | 'test' | 'production';\n\ntype OptionalMigrationDefaults = {\n dialect?: Dialect;\n db?: string;\n dir?: string;\n autoApply?: boolean;\n};\n\ntype ModelMetadataLike = {\n table: string;\n fields: Array<{\n name: string;\n type: ColumnType;\n notNull?: boolean;\n default?: string | { now: true } | null;\n primaryKey?: boolean;\n unique?: boolean;\n references?: {\n table: string;\n column: string;\n onDelete?: DeleteReferentialAction;\n onUpdate?: UpdateReferentialAction;\n };\n }>;\n indexes?: Array<{ name: string; on: string[]; unique?: boolean }>;\n};\n\ntype CliDbClient = {\n query<T = unknown>(sql: string, params?: readonly unknown[]): Promise<{ rows: T[] }>;\n close(): Promise<void>;\n};\n\ntype LoadedModelsResult = {\n models: ModelMetadataLike[];\n registry: ModelRegistry;\n modelTypeAccessors: Record<string, string>;\n};\n\ntype ModelContainerLike = {\n metadata: ModelMetadataLike;\n};\n\nasync function importModule(modulePath: string): Promise<Record<string, unknown>> {\n return loadModule(modulePath, { projectRoot: process.cwd() });\n}\n\nasync function tryLoadMigrationDefaults(\n configPathArg: string | undefined,\n configEnvArg: ConfigEnvironment | undefined\n): Promise<OptionalMigrationDefaults> {\n const explicitConfigPath = typeof configPathArg === 'string' && configPathArg.trim().length > 0;\n const resolvedPath = resolve(process.cwd(), configPathArg?.trim() || './tango.config.ts');\n\n try {\n await access(resolvedPath, fsConstants.F_OK);\n } catch (error) {\n if (explicitConfigPath) {\n throw new Error(`Config file not found: ${resolvedPath}`, { cause: error });\n }\n return {};\n }\n\n const module = await importModule(resolvedPath);\n const fileConfig = (module.default ?? module) as { current?: ConfigEnvironment } & Record<string, unknown>;\n\n const loaded = loadConfig(() => ({\n ...fileConfig,\n ...(configEnvArg ? { current: configEnvArg } : {}),\n }));\n\n const { db, migrations } = loaded.current;\n const inferredDialect = db.adapter as Dialect;\n const inferredDb = resolveDbTarget(db);\n\n return {\n dialect: inferredDialect,\n db: inferredDb,\n dir: migrations.dir,\n autoApply: (migrations as { autoApply?: boolean }).autoApply,\n };\n}\n\nfunction resolveDbTarget(db: {\n adapter: string;\n url?: string;\n filename?: string;\n host?: string;\n port?: number;\n database?: string;\n user?: string;\n password?: string;\n}): string | undefined {\n if (db.adapter === InternalDialect.SQLITE) {\n return db.filename ?? db.url;\n }\n\n if (db.url) {\n return db.url;\n }\n\n if (!db.database) {\n return undefined;\n }\n\n const host = db.host ?? 'localhost';\n const port = db.port ?? 5432;\n const encodedUser = db.user ? encodeURIComponent(db.user) : '';\n const encodedPassword = db.password ? encodeURIComponent(db.password) : '';\n const userInfo =\n encodedUser.length > 0\n ? encodedPassword.length > 0\n ? `${encodedUser}:${encodedPassword}@`\n : `${encodedUser}@`\n : '';\n\n return `postgres://${userInfo}${host}:${String(port)}/${db.database}`;\n}\n\nasync function resolveCommandInputs(argv: {\n dialect?: string;\n dir?: string;\n db?: string;\n config?: string;\n env?: ConfigEnvironment;\n}): Promise<{ dialect: Dialect; dir: string; db?: string; autoApply: boolean }> {\n const defaults = await tryLoadMigrationDefaults(argv.config, argv.env);\n\n const resolvedDialect = (argv.dialect as Dialect | undefined) ?? defaults.dialect ?? InternalDialect.POSTGRES;\n const resolvedDir = argv.dir ?? defaults.dir ?? 'migrations';\n const resolvedDb = argv.db ?? defaults.db;\n\n return {\n dialect: resolvedDialect,\n dir: resolvedDir,\n db: resolvedDb,\n autoApply: defaults.autoApply ?? true,\n };\n}\n\nfunction isModelContainerLike(value: unknown): value is ModelContainerLike {\n return typeof value === 'object' && value !== null && 'metadata' in value;\n}\n\nfunction collectExportedModels(moduleValue: unknown): ModelMetadataLike[] {\n if (!moduleValue || typeof moduleValue !== 'object') {\n return [];\n }\n\n const models: ModelMetadataLike[] = [];\n for (const value of Object.values(moduleValue as Record<string, unknown>)) {\n if (isModelContainerLike(value)) {\n models.push(value.metadata);\n continue;\n }\n\n if (!value || typeof value !== 'object') {\n continue;\n }\n\n for (const nestedValue of Object.values(value as Record<string, unknown>)) {\n if (isModelContainerLike(nestedValue)) {\n models.push(nestedValue.metadata);\n }\n }\n }\n\n return models;\n}\n\nasync function loadModels(modelsPath: string): Promise<LoadedModelsResult> {\n const {\n loaded: mod,\n registry,\n modelTypeAccessors,\n } = await loadProjectModule(modelsPath, {\n projectRoot: process.cwd(),\n outputDir: resolve(process.cwd(), GENERATED_RELATION_REGISTRY_DIRNAME),\n });\n const moduleValue = (mod.default ?? mod) as unknown;\n\n const models = isModelContainerLike(moduleValue)\n ? [moduleValue.metadata, ...collectExportedModels(moduleValue)]\n : collectExportedModels(moduleValue);\n\n if (models.length === 0) {\n throw new Error(`No models found in '${modelsPath}'. Ensure the module exports Model() definitions.`);\n }\n\n return {\n models,\n registry,\n modelTypeAccessors,\n };\n}\n\nasync function connectAndIntrospect(dbUrl: string, dialect: string): Promise<DbSchema> {\n const dbClient = await connectDbClient(dbUrl, dialect as Dialect);\n\n try {\n const strategy = createDefaultIntrospectorStrategy();\n return await strategy.introspect(dialect as Dialect, dbClient);\n } finally {\n await dbClient.close();\n }\n}\n\nasync function connectDbClient(db: string, dialect: Dialect): Promise<CliDbClient> {\n if (dialect === InternalDialect.POSTGRES) {\n const pg = await import('pg');\n const client = new pg.default.Client({ connectionString: db });\n await client.connect();\n\n return {\n async query<T = unknown>(sql: string, params?: readonly unknown[]): Promise<{ rows: T[] }> {\n const result = await client.query(sql, params as unknown[] | undefined);\n return { rows: result.rows as T[] };\n },\n async close(): Promise<void> {\n await client.end();\n },\n };\n }\n\n if (dialect === InternalDialect.SQLITE) {\n const sqlite = await import('better-sqlite3');\n const DatabaseCtor = (sqlite.default ?? sqlite) as new (filename: string) => {\n prepare(sql: string): {\n all(...params: unknown[]): unknown[];\n run(...params: unknown[]): unknown;\n };\n close(): void;\n };\n\n const filename = normalizeSqliteFilename(db);\n await ensureSqliteParentDirectory(filename);\n const connection = new DatabaseCtor(filename);\n\n return {\n async query<T = unknown>(sql: string, params?: readonly unknown[]): Promise<{ rows: T[] }> {\n const statement = connection.prepare(sql);\n const values = [...(params ?? [])];\n const isSelectLike = /^\\s*(SELECT|PRAGMA|WITH)\\b/i.test(sql);\n if (isSelectLike) {\n return { rows: statement.all(...values) as T[] };\n }\n\n statement.run(...values);\n return { rows: [] as T[] };\n },\n async close(): Promise<void> {\n connection.close();\n },\n };\n }\n\n throw new Error(`Unsupported dialect: ${dialect}`);\n}\n\nasync function ensureSqliteParentDirectory(filename: string): Promise<void> {\n if (filename === ':memory:' || filename === 'file::memory:') {\n return;\n }\n const directory = dirname(filename);\n if (directory === '.' || directory.length === 0) {\n return;\n }\n await mkdir(directory, { recursive: true });\n}\n\nfunction normalizeSqliteFilename(db: string): string {\n if (db.startsWith('sqlite://')) {\n return db.slice('sqlite://'.length);\n }\n return db;\n}\n\n/**\n * Register Tango's migration commands on an existing yargs parser.\n */\nexport function registerMigrationsCommands(yargsBuilder: Argv): Argv {\n return yargsBuilder\n .command(\n 'migrate',\n 'Apply pending migrations to the database',\n (builder) =>\n builder\n .option('dir', {\n type: 'string',\n describe: 'Migrations directory',\n })\n .option('db', {\n type: 'string',\n describe: 'Database connection URL',\n })\n .option('dialect', {\n type: 'string',\n choices: ['postgres', 'sqlite'] as const,\n describe: 'Database dialect',\n })\n .option('config', {\n type: 'string',\n describe: 'Path to tango.config.ts (auto-loads ./tango.config.ts when present)',\n })\n .option('env', {\n type: 'string',\n choices: ['development', 'test', 'production'] as const,\n describe: 'Config environment override',\n })\n .option('to', {\n type: 'string',\n describe: 'Target migration ID (apply up to this migration)',\n }),\n async (argv) => {\n const resolved = await resolveCommandInputs({\n dialect: argv.dialect as string | undefined,\n dir: argv.dir as string | undefined,\n db: argv.db as string | undefined,\n config: argv.config as string | undefined,\n env: argv.env as ConfigEnvironment | undefined,\n });\n\n if (!resolved.autoApply) {\n logger.info('Auto-migration disabled (autoApply: false). Skipping.');\n return;\n }\n\n if (!resolved.db) {\n throw new Error('No database target provided. Pass --db or define db settings in tango.config.ts.');\n }\n\n const dbClient = await connectDbClient(resolved.db, resolved.dialect);\n\n const runner = new MigrationRunner(dbClient, resolved.dialect, resolved.dir);\n await runner.apply(argv.to);\n\n await dbClient.close();\n logger.info('Migrations applied successfully');\n }\n )\n .command(\n 'make:migrations',\n 'Generate migration file by comparing models to database',\n (builder) =>\n builder\n .option('dir', {\n type: 'string',\n describe: 'Migrations directory',\n })\n .option('name', {\n type: 'string',\n demandOption: true,\n describe: 'Migration name (e.g. \"create_users\")',\n })\n .option('models', {\n type: 'string',\n demandOption: true,\n describe: 'Path to module exporting Model definitions (e.g. \"./src/models.ts\")',\n })\n .option('db', {\n type: 'string',\n describe: 'Database connection URL for introspection (omit for initial migration)',\n })\n .option('dialect', {\n type: 'string',\n choices: ['postgres', 'sqlite'] as const,\n describe: 'Database dialect',\n })\n .option('config', {\n type: 'string',\n describe: 'Path to tango.config.ts (auto-loads ./tango.config.ts when present)',\n })\n .option('env', {\n type: 'string',\n choices: ['development', 'test', 'production'] as const,\n describe: 'Config environment override',\n }),\n async (argv) => {\n const resolved = await resolveCommandInputs({\n dialect: argv.dialect as string | undefined,\n dir: argv.dir as string | undefined,\n db: argv.db as string | undefined,\n config: argv.config as string | undefined,\n env: argv.env as ConfigEnvironment | undefined,\n });\n const loaded = await loadModels(argv.models);\n const projectedModels = buildMigrationModelMetadataProjection(loaded.registry);\n logger.info(\n `Found ${loaded.models.length} exported model(s); ${projectedModels.length} model(s) after projection: ${projectedModels.map((m) => m.table).join(', ')}`\n );\n try {\n await writeRelationRegistryArtifacts({\n registry: loaded.registry,\n modelTypeAccessors: loaded.modelTypeAccessors,\n outputDir: resolve(process.cwd(), GENERATED_RELATION_REGISTRY_DIRNAME),\n });\n } catch (error) {\n logger.warn(\n `Unable to refresh generated relation registry during make:migrations. Continuing without updated relation artifacts: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n\n let dbState: DbSchema;\n if (resolved.db) {\n logger.info('Introspecting database...');\n dbState = await connectAndIntrospect(resolved.db, resolved.dialect);\n } else {\n dbState = { tables: {} };\n }\n\n const operations = diffSchema(dbState, projectedModels);\n\n if (operations.length === 0) {\n logger.info('No changes detected — models and database are in sync');\n return;\n }\n\n const generator = new MigrationGenerator();\n const filepath = await generator.generate({\n name: argv.name,\n operations,\n directory: resolved.dir,\n });\n\n logger.info(`Generated migration: ${filepath}`);\n logger.info(` ${operations.length} operation(s)`);\n }\n )\n .command(\n 'plan',\n 'Print migration SQL without applying',\n (builder) =>\n builder\n .option('dir', {\n type: 'string',\n describe: 'Migrations directory',\n })\n .option('dialect', {\n type: 'string',\n choices: ['postgres', 'sqlite'] as const,\n describe: 'Database dialect',\n })\n .option('config', {\n type: 'string',\n describe: 'Path to tango.config.ts (auto-loads ./tango.config.ts when present)',\n })\n .option('env', {\n type: 'string',\n choices: ['development', 'test', 'production'] as const,\n describe: 'Config environment override',\n }),\n async (argv) => {\n const resolved = await resolveCommandInputs({\n dialect: argv.dialect as string | undefined,\n dir: argv.dir as string | undefined,\n db: argv.db as string | undefined,\n config: argv.config as string | undefined,\n env: argv.env as ConfigEnvironment | undefined,\n });\n const runner = new MigrationRunner(\n { query: async () => ({ rows: [] }), close: async () => {} },\n resolved.dialect,\n resolved.dir\n );\n const output = await runner.plan();\n logger.info(output);\n }\n )\n .command(\n 'status',\n 'Show applied/pending status of all migrations',\n (builder) =>\n builder\n .option('dir', {\n type: 'string',\n describe: 'Migrations directory',\n })\n .option('db', {\n type: 'string',\n describe: 'Database connection URL',\n })\n .option('dialect', {\n type: 'string',\n choices: ['postgres', 'sqlite'] as const,\n describe: 'Database dialect',\n })\n .option('config', {\n type: 'string',\n describe: 'Path to tango.config.ts (auto-loads ./tango.config.ts when present)',\n })\n .option('env', {\n type: 'string',\n choices: ['development', 'test', 'production'] as const,\n describe: 'Config environment override',\n }),\n async (argv) => {\n const resolved = await resolveCommandInputs({\n dialect: argv.dialect as string | undefined,\n dir: argv.dir as string | undefined,\n db: argv.db as string | undefined,\n config: argv.config as string | undefined,\n env: argv.env as ConfigEnvironment | undefined,\n });\n if (!resolved.db) {\n throw new Error('No database target provided. Pass --db or define db settings in tango.config.ts.');\n }\n\n const dbClient = await connectDbClient(resolved.db, resolved.dialect);\n\n const runner = new MigrationRunner(dbClient, resolved.dialect, resolved.dir);\n const statuses = await runner.status();\n\n if (statuses.length === 0) {\n logger.info('No migrations found');\n } else {\n statuses.forEach((statusItem) => {\n const marker = statusItem.applied ? '[x]' : '[ ]';\n logger.info(` ${marker} ${statusItem.id}`);\n });\n }\n\n await dbClient.close();\n }\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAqBA,MAAM,SAAS,UAAU,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e;GAAQ;EAAa;EAC9C,UAAU;CACb,EAAC,EACV,OAAO,SAAS;EACZ,MAAM,WAAW,MAAM,qBAAqB;GACxC,SAAS,KAAK;GACd,KAAK,KAAK;GACV,IAAI,KAAK;GACT,QAAQ,KAAK;GACb,KAAK,KAAK;EACb,EAAC;AACF,OAAK,SAAS,GACV,OAAM,IAAI,MAAM;EAGpB,MAAM,WAAW,MAAM,gBAAgB,SAAS,IAAI,SAAS,QAAQ;EAErE,MAAM,SAAS,IAAI,gBAAgB,UAAU,SAAS,SAAS,SAAS;EACxE,MAAM,WAAW,MAAM,OAAO,QAAQ;AAEtC,MAAI,SAAS,WAAW,EACpB,QAAO,KAAK,sBAAsB;IAElC,UAAS,QAAQ,CAAC,eAAe;GAC7B,MAAM,SAAS,WAAW,UAAU,QAAQ;AAC5C,UAAO,MAAM,IAAI,OAAO,GAAG,WAAW,GAAG,EAAE;EAC9C,EAAC;AAGN,QAAM,SAAS,OAAO;CACzB,EACJ;AACR"}
|
package/dist/cli.js
CHANGED
|
@@ -4,15 +4,15 @@ import "./Migration-DYQ0hUG7.js";
|
|
|
4
4
|
import "./InternalOperationKind-Bt6Weuon.js";
|
|
5
5
|
import "./InternalColumnType-G9zV9StN.js";
|
|
6
6
|
import "./MigrationSqlSafetyAdapter-CGRbB2k2.js";
|
|
7
|
-
import "./SqliteCompilerFactory-
|
|
8
|
-
import "./CompilerStrategy-
|
|
9
|
-
import "./MigrationRunner-
|
|
7
|
+
import "./SqliteCompilerFactory-BvdJ0kBl.js";
|
|
8
|
+
import "./CompilerStrategy-_AiXiyjS.js";
|
|
9
|
+
import "./MigrationRunner-DomrOZIn.js";
|
|
10
10
|
import "./MigrationGenerator-B1p0jHnx.js";
|
|
11
11
|
import "./builder-xJ-Bq2pk.js";
|
|
12
|
-
import "./
|
|
12
|
+
import "./diff-B9MhagJF.js";
|
|
13
13
|
import "./SqliteIntrospector-CWwPWhmA.js";
|
|
14
|
-
import "./IntrospectorStrategy-
|
|
15
|
-
import { registerMigrationsCommands } from "./cli-
|
|
14
|
+
import "./IntrospectorStrategy-BEIG5GqA.js";
|
|
15
|
+
import { registerMigrationsCommands } from "./cli-7j3R1Y1r.js";
|
|
16
16
|
import yargs from "yargs";
|
|
17
17
|
import { hideBin } from "yargs/helpers";
|
|
18
18
|
|
package/dist/commands/index.js
CHANGED
|
@@ -3,15 +3,15 @@ import "../Migration-DYQ0hUG7.js";
|
|
|
3
3
|
import "../InternalOperationKind-Bt6Weuon.js";
|
|
4
4
|
import "../InternalColumnType-G9zV9StN.js";
|
|
5
5
|
import "../MigrationSqlSafetyAdapter-CGRbB2k2.js";
|
|
6
|
-
import "../SqliteCompilerFactory-
|
|
7
|
-
import "../CompilerStrategy-
|
|
8
|
-
import "../MigrationRunner-
|
|
6
|
+
import "../SqliteCompilerFactory-BvdJ0kBl.js";
|
|
7
|
+
import "../CompilerStrategy-_AiXiyjS.js";
|
|
8
|
+
import "../MigrationRunner-DomrOZIn.js";
|
|
9
9
|
import "../MigrationGenerator-B1p0jHnx.js";
|
|
10
10
|
import "../builder-xJ-Bq2pk.js";
|
|
11
|
-
import "../
|
|
11
|
+
import "../diff-B9MhagJF.js";
|
|
12
12
|
import "../SqliteIntrospector-CWwPWhmA.js";
|
|
13
|
-
import "../IntrospectorStrategy-
|
|
14
|
-
import { registerMigrationsCommands } from "../cli-
|
|
15
|
-
import "../commands-
|
|
13
|
+
import "../IntrospectorStrategy-BEIG5GqA.js";
|
|
14
|
+
import { registerMigrationsCommands } from "../cli-7j3R1Y1r.js";
|
|
15
|
+
import "../commands-Cl2MU7tq.js";
|
|
16
16
|
|
|
17
17
|
export { registerMigrationsCommands };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __export } from "./chunk-BkvOhyD0.js";
|
|
2
|
-
import { registerMigrationsCommands } from "./cli-
|
|
2
|
+
import { registerMigrationsCommands } from "./cli-7j3R1Y1r.js";
|
|
3
3
|
|
|
4
4
|
//#region src/commands/index.ts
|
|
5
5
|
var commands_exports = {};
|
|
@@ -7,4 +7,4 @@ __export(commands_exports, { registerMigrationsCommands: () => registerMigration
|
|
|
7
7
|
|
|
8
8
|
//#endregion
|
|
9
9
|
export { commands_exports };
|
|
10
|
-
//# sourceMappingURL=commands-
|
|
10
|
+
//# sourceMappingURL=commands-Cl2MU7tq.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands-
|
|
1
|
+
{"version":3,"file":"commands-Cl2MU7tq.js","names":[],"sources":["../src/commands/index.ts"],"sourcesContent":["/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\n\nexport { registerMigrationsCommands } from './cli';\n"],"mappings":""}
|
|
@@ -4,6 +4,8 @@ import type { SQL } from './SQL';
|
|
|
4
4
|
* Contract for dialect-specific migration SQL compilers.
|
|
5
5
|
*/
|
|
6
6
|
export interface SQLCompiler {
|
|
7
|
+
/** Prepare operations into the dialect-specific execution order. */
|
|
8
|
+
prepareOperations?(operations: MigrationOperation[]): MigrationOperation[];
|
|
7
9
|
/** Compile an operation into SQL statements. */
|
|
8
10
|
compile(operation: MigrationOperation): SQL[];
|
|
9
11
|
}
|
|
@@ -12,6 +12,11 @@ export declare class PostgresCompiler implements SQLCompiler {
|
|
|
12
12
|
* Narrow an unknown value to the PostgreSQL migration compiler implementation.
|
|
13
13
|
*/
|
|
14
14
|
static isPostgresCompiler(value: unknown): value is PostgresCompiler;
|
|
15
|
+
/**
|
|
16
|
+
* Rewrite migration operations into PostgreSQL's preferred execution
|
|
17
|
+
* order, including separating inline foreign keys from table creation.
|
|
18
|
+
*/
|
|
19
|
+
prepareOperations(operations: MigrationOperation[]): MigrationOperation[];
|
|
15
20
|
/**
|
|
16
21
|
* Compile a migration operation into one or more PostgreSQL statements.
|
|
17
22
|
*/
|
|
@@ -21,6 +26,7 @@ export declare class PostgresCompiler implements SQLCompiler {
|
|
|
21
26
|
* Extracted to flatten the nested conditional logic.
|
|
22
27
|
*/
|
|
23
28
|
private compileDefaultChange;
|
|
29
|
+
private stripTableCreateForeignKeys;
|
|
24
30
|
private colDDL;
|
|
25
31
|
private typeToSQL;
|
|
26
32
|
}
|