@danceroutine/tango-migrations 1.11.1 → 1.11.3

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.
Files changed (142) hide show
  1. package/dist/Builder-y8vj7XXN.d.ts +25 -0
  2. package/dist/{CollectingBuilder--4fqDQdE.js → CollectingBuilder-BIfAKs_x.js} +6 -4
  3. package/dist/CollectingBuilder-BIfAKs_x.js.map +1 -0
  4. package/dist/CompilerFactory-Czv-zEOS.d.ts +30 -0
  5. package/dist/CompilerStrategy-DqmcqAC-.d.ts +44 -0
  6. package/dist/{CompilerStrategy-_AiXiyjS.js → CompilerStrategy-vcZKg8qf.js} +14 -10
  7. package/dist/CompilerStrategy-vcZKg8qf.js.map +1 -0
  8. package/dist/Dialect-Cp4r7UfW.d.ts +12 -0
  9. package/dist/{InternalColumnType-G9zV9StN.js → InternalColumnType-Dzs9T6a6.js} +3 -4
  10. package/dist/{InternalColumnType-G9zV9StN.js.map → InternalColumnType-Dzs9T6a6.js.map} +1 -1
  11. package/dist/{InternalOperationKind-Bt6Weuon.js → InternalOperationKind-M4a4H9OZ.js} +3 -4
  12. package/dist/{InternalOperationKind-Bt6Weuon.js.map → InternalOperationKind-M4a4H9OZ.js.map} +1 -1
  13. package/dist/{IntrospectorStrategy-BEIG5GqA.js → IntrospectorStrategy-BijuyIaN.js} +14 -9
  14. package/dist/IntrospectorStrategy-BijuyIaN.js.map +1 -0
  15. package/dist/{Migration-DYQ0hUG7.js → Migration-DxHHPyzn.js} +9 -4
  16. package/dist/Migration-DxHHPyzn.js.map +1 -0
  17. package/dist/{MigrationGenerator-B1p0jHnx.js → MigrationGenerator-BmmerPXJ.js} +24 -35
  18. package/dist/MigrationGenerator-BmmerPXJ.js.map +1 -0
  19. package/dist/MigrationOperation-qpdhPEs9.d.ts +145 -0
  20. package/dist/{MigrationRunner-DomrOZIn.js → MigrationRunner-B5AJel12.js} +52 -24
  21. package/dist/MigrationRunner-B5AJel12.js.map +1 -0
  22. package/dist/{MigrationSqlSafetyAdapter-CGRbB2k2.js → MigrationSqlSafetyAdapter-yP6fPjeC.js} +13 -9
  23. package/dist/MigrationSqlSafetyAdapter-yP6fPjeC.js.map +1 -0
  24. package/dist/PostgresIntrospector-DQDTZUW_.d.ts +77 -0
  25. package/dist/{SqliteCompilerFactory-BvdJ0kBl.js → SqliteCompilerFactory-CXlPAclY.js} +38 -40
  26. package/dist/SqliteCompilerFactory-CXlPAclY.js.map +1 -0
  27. package/dist/{SqliteIntrospector-CWwPWhmA.js → SqliteIntrospector-CfItmGgA.js} +15 -15
  28. package/dist/SqliteIntrospector-CfItmGgA.js.map +1 -0
  29. package/dist/builder/index.d.ts +4 -10
  30. package/dist/builder/index.js +3 -6
  31. package/dist/{builder-xJ-Bq2pk.js → builder-BSepa_PF.js} +24 -24
  32. package/dist/builder-BSepa_PF.js.map +1 -0
  33. package/dist/chunk-D7D4PA-g.js +13 -0
  34. package/dist/{cli-7j3R1Y1r.js → cli-e8I1-dab.js} +34 -47
  35. package/dist/cli-e8I1-dab.js.map +1 -0
  36. package/dist/cli.d.ts +1 -2
  37. package/dist/cli.js +3 -16
  38. package/dist/cli.js.map +1 -1
  39. package/dist/commands/index.d.ts +2 -4
  40. package/dist/commands/index.js +7 -16
  41. package/dist/commands/index.js.map +1 -0
  42. package/dist/compilers/index.d.ts +3 -10
  43. package/dist/compilers/index.js +3 -7
  44. package/dist/{compilers-C-GiumJB.js → compilers-BW-WALoD.js} +9 -16
  45. package/dist/{compilers-C-GiumJB.js.map → compilers-BW-WALoD.js.map} +1 -1
  46. package/dist/diff/index.d.ts +2 -5
  47. package/dist/diff/index.js +2 -7
  48. package/dist/{diff-B9MhagJF.js → diff-7Xw8k4vp.js} +14 -14
  49. package/dist/diff-7Xw8k4vp.js.map +1 -0
  50. package/dist/domain/index.d.ts +5 -7
  51. package/dist/domain/index.js +7 -3
  52. package/dist/domain/index.js.map +1 -0
  53. package/dist/generator/index.d.ts +2 -4
  54. package/dist/generator/index.js +7 -4
  55. package/dist/generator/index.js.map +1 -0
  56. package/dist/index-B8VoE0M4.d.ts +56 -0
  57. package/dist/index-CsTGwtZ0.d.ts +110 -0
  58. package/dist/index-CzdR_Ig9.d.ts +47 -0
  59. package/dist/index-CzpjLzoS.d.ts +180 -0
  60. package/dist/index-D7qe9iKG.d.ts +13 -0
  61. package/dist/index-DdCF5yCg.d.ts +38 -0
  62. package/dist/index-a1Y--85Y.d.ts +41 -0
  63. package/dist/index-ni7Db8Lv.d.ts +86 -0
  64. package/dist/index-sywIP4pt.d.ts +61 -0
  65. package/dist/index.d.ts +17 -27
  66. package/dist/index.js +19 -23
  67. package/dist/introspect/index.d.ts +3 -6
  68. package/dist/introspect/index.js +10 -4
  69. package/dist/introspect/index.js.map +1 -0
  70. package/dist/runner/index.d.ts +2 -4
  71. package/dist/runner/index.js +7 -10
  72. package/dist/runner/index.js.map +1 -0
  73. package/dist/strategies/index.d.ts +3 -5
  74. package/dist/strategies/index.js +13 -9
  75. package/dist/strategies/index.js.map +1 -0
  76. package/package.json +9 -9
  77. package/dist/CollectingBuilder--4fqDQdE.js.map +0 -1
  78. package/dist/CompilerStrategy-_AiXiyjS.js.map +0 -1
  79. package/dist/IntrospectorStrategy-BEIG5GqA.js.map +0 -1
  80. package/dist/Migration-DYQ0hUG7.js.map +0 -1
  81. package/dist/MigrationGenerator-B1p0jHnx.js.map +0 -1
  82. package/dist/MigrationRunner-DomrOZIn.js.map +0 -1
  83. package/dist/MigrationSqlSafetyAdapter-CGRbB2k2.js.map +0 -1
  84. package/dist/SqliteCompilerFactory-BvdJ0kBl.js.map +0 -1
  85. package/dist/SqliteIntrospector-CWwPWhmA.js.map +0 -1
  86. package/dist/builder/contracts/Builder.d.ts +0 -11
  87. package/dist/builder/contracts/ColumnSpec.d.ts +0 -20
  88. package/dist/builder/contracts/ColumnType.d.ts +0 -2
  89. package/dist/builder/contracts/DeleteReferentialAction.d.ts +0 -2
  90. package/dist/builder/contracts/UpdateReferentialAction.d.ts +0 -2
  91. package/dist/builder/contracts/index.d.ts +0 -8
  92. package/dist/builder/ops/OpBuilder.d.ts +0 -129
  93. package/dist/builder/ops/index.d.ts +0 -4
  94. package/dist/builder/runtime/CollectingBuilder.d.ts +0 -39
  95. package/dist/builder/runtime/index.d.ts +0 -4
  96. package/dist/builder-xJ-Bq2pk.js.map +0 -1
  97. package/dist/chunk-BkvOhyD0.js +0 -12
  98. package/dist/cli-7j3R1Y1r.js.map +0 -1
  99. package/dist/commands/cli.d.ts +0 -5
  100. package/dist/commands-Cl2MU7tq.js +0 -10
  101. package/dist/commands-Cl2MU7tq.js.map +0 -1
  102. package/dist/compilers/contracts/CompilerFactory.d.ts +0 -8
  103. package/dist/compilers/contracts/SQL.d.ts +0 -4
  104. package/dist/compilers/contracts/SQLCompiler.d.ts +0 -11
  105. package/dist/compilers/contracts/index.d.ts +0 -6
  106. package/dist/compilers/dialects/PostgresCompiler.d.ts +0 -32
  107. package/dist/compilers/dialects/SqliteCompiler.d.ts +0 -27
  108. package/dist/compilers/dialects/index.d.ts +0 -5
  109. package/dist/compilers/factories/PostgresCompilerFactory.d.ts +0 -17
  110. package/dist/compilers/factories/SqliteCompilerFactory.d.ts +0 -17
  111. package/dist/compilers/factories/index.d.ts +0 -5
  112. package/dist/diff/diffSchema.d.ts +0 -39
  113. package/dist/diff-B9MhagJF.js.map +0 -1
  114. package/dist/domain/Dialect.d.ts +0 -2
  115. package/dist/domain/Migration.d.ts +0 -29
  116. package/dist/domain/MigrationMode.d.ts +0 -2
  117. package/dist/domain/MigrationOperation.d.ts +0 -77
  118. package/dist/domain/internal/InternalColumnType.d.ts +0 -11
  119. package/dist/domain/internal/InternalDialect.d.ts +0 -5
  120. package/dist/domain/internal/InternalMigrationMode.d.ts +0 -5
  121. package/dist/domain/internal/InternalOperationKind.d.ts +0 -14
  122. package/dist/domain/internal/InternalReferentialAction.d.ts +0 -7
  123. package/dist/domain-CwR-kUNS.js +0 -10
  124. package/dist/domain-CwR-kUNS.js.map +0 -1
  125. package/dist/generator/MigrationGenerator.d.ts +0 -48
  126. package/dist/generator-DK-_f-PF.js +0 -10
  127. package/dist/generator-DK-_f-PF.js.map +0 -1
  128. package/dist/internal/MigrationSqlSafetyAdapter.d.ts +0 -24
  129. package/dist/introspect/DatabaseIntrospector.d.ts +0 -17
  130. package/dist/introspect/PostgresIntrospector.d.ts +0 -56
  131. package/dist/introspect/SqliteIntrospector.d.ts +0 -53
  132. package/dist/introspect-DD3fm15e.js +0 -13
  133. package/dist/introspect-DD3fm15e.js.map +0 -1
  134. package/dist/runner/MigrationRunner.d.ts +0 -79
  135. package/dist/runner-C97xT8_W.js +0 -10
  136. package/dist/runner-C97xT8_W.js.map +0 -1
  137. package/dist/runtime/loadModule.d.ts +0 -18
  138. package/dist/schema/buildMigrationModelMetadataProjection.d.ts +0 -3
  139. package/dist/strategies/CompilerStrategy.d.ts +0 -42
  140. package/dist/strategies/IntrospectorStrategy.d.ts +0 -34
  141. package/dist/strategies-HwUWvmLC.js +0 -16
  142. package/dist/strategies-HwUWvmLC.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqliteCompilerFactory-CXlPAclY.js","names":["exhaustive"],"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":";;;;;;;AAYA,IAAa,mBAAb,MAAa,iBAAwC;CAC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B,OAAO,CAAC,GAAG,OAAO,EAAE,MAAM,MAAM,UAAU,KAAK,MAAM,cAAc,MAAM,KAAK,CAAC;EAGnF,OAAO;CACX;AACJ;;;;;;ACpQA,IAAa,wBAAb,MAAa,sBAAiD;CAC1D,OAAgB,QAAQ;CACxB,eAA4D,sBAAsB;;;;CAKlF,OAAO,wBAAwB,OAAgD;EAC3E,OACI,OAAO,UAAU,YACjB,UAAU,QACT,MAAqC,iBAAiB,sBAAsB;CAErF;;;;CAKA,SAAsB;EAClB,OAAO,IAAI,eAAe;CAC9B;AACJ"}
@@ -1,6 +1,8 @@
1
- import { MigrationSqlSafetyAdapter } from "./MigrationSqlSafetyAdapter-CGRbB2k2.js";
2
-
1
+ import { t as MigrationSqlSafetyAdapter } from "./MigrationSqlSafetyAdapter-yP6fPjeC.js";
3
2
  //#region src/introspect/PostgresIntrospector.ts
3
+ /**
4
+ * PostgreSQL implementation of schema introspection.
5
+ */
4
6
  var PostgresIntrospector = class PostgresIntrospector {
5
7
  static BRAND = "tango.migrations.postgres_introspector";
6
8
  __tangoBrand = PostgresIntrospector.BRAND;
@@ -33,14 +35,13 @@ var PostgresIntrospector = class PostgresIntrospector {
33
35
  WHERE a.attrelid = '${tableRow.tbl_oid}'::oid AND a.attnum > 0 AND NOT a.attisdropped
34
36
  ORDER BY a.attnum
35
37
  `);
36
- const pkRes = await client.query(`
38
+ const pks = (await client.query(`
37
39
  SELECT a.attname AS col
38
40
  FROM pg_index i
39
41
  JOIN pg_attribute a ON a.attrelid = i.indrelid AND a.attnum = ANY(i.indkey)
40
42
  WHERE i.indrelid = '${tableRow.tbl_oid}'::oid AND i.indisprimary
41
- `);
42
- const pks = pkRes.rows.map((pkRow) => pkRow.col);
43
- const idxRes = await client.query(`
43
+ `)).rows.map((pkRow) => pkRow.col);
44
+ const indexes = (await client.query(`
44
45
  SELECT
45
46
  idx.relname AS name,
46
47
  i.indisunique AS unique,
@@ -57,8 +58,7 @@ var PostgresIntrospector = class PostgresIntrospector {
57
58
  WHERE i.indrelid = '${tableRow.tbl_oid}'::oid
58
59
  AND NOT i.indisprimary
59
60
  AND con.oid IS NULL
60
- `);
61
- const indexes = idxRes.rows.reduce((accumulator, indexRow) => {
61
+ `)).rows.reduce((accumulator, indexRow) => {
62
62
  const name = String(indexRow.name);
63
63
  accumulator[name] = {
64
64
  name,
@@ -93,9 +93,11 @@ var PostgresIntrospector = class PostgresIntrospector {
93
93
  return schema;
94
94
  }
95
95
  };
96
-
97
96
  //#endregion
98
97
  //#region src/introspect/SqliteIntrospector.ts
98
+ /**
99
+ * SQLite implementation of schema introspection.
100
+ */
99
101
  var SqliteIntrospector = class SqliteIntrospector {
100
102
  static BRAND = "tango.migrations.sqlite_introspector";
101
103
  __tangoBrand = SqliteIntrospector.BRAND;
@@ -138,12 +140,10 @@ var SqliteIntrospector = class SqliteIntrospector {
138
140
  for (const indexRow of indexListRes.rows) {
139
141
  const name = String(indexRow.name);
140
142
  if (name.startsWith("sqlite_autoindex_")) continue;
141
- const indexInfoRes = await client.query(`PRAGMA index_info(${this.sqlSafety.index(name)})`);
142
- const on = indexInfoRes.rows.map((infoRow) => String(infoRow.name)).filter(Boolean);
143
143
  indexes[name] = {
144
144
  name,
145
145
  table,
146
- columns: on,
146
+ columns: (await client.query(`PRAGMA index_info(${this.sqlSafety.index(name)})`)).rows.map((infoRow) => String(infoRow.name)).filter(Boolean),
147
147
  unique: indexRow.unique === 1,
148
148
  where: null
149
149
  };
@@ -159,7 +159,7 @@ var SqliteIntrospector = class SqliteIntrospector {
159
159
  return schema;
160
160
  }
161
161
  };
162
-
163
162
  //#endregion
164
- export { PostgresIntrospector, SqliteIntrospector };
165
- //# sourceMappingURL=SqliteIntrospector-CWwPWhmA.js.map
163
+ export { PostgresIntrospector as n, SqliteIntrospector as t };
164
+
165
+ //# sourceMappingURL=SqliteIntrospector-CfItmGgA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqliteIntrospector-CfItmGgA.js","names":[],"sources":["../src/introspect/PostgresIntrospector.ts","../src/introspect/SqliteIntrospector.ts"],"sourcesContent":["import type { DBClient, DatabaseIntrospector } from './DatabaseIntrospector';\n\n/** Introspected column metadata. */\nexport interface DbColumn {\n name: string;\n type: string;\n notNull: boolean;\n default: string | null;\n isPk: boolean;\n isUnique: boolean;\n}\n\n/** Introspected index metadata. */\nexport interface DbIndex {\n name: string;\n table: string;\n unique: boolean;\n columns: string[];\n where: string | null;\n}\n\n/** Introspected foreign key metadata. */\nexport interface DbForeignKey {\n name: string;\n table: string;\n columns: string[];\n refTable: string;\n refColumns: string[];\n onDelete: string | null;\n onUpdate: string | null;\n validated: boolean;\n}\n\n/** Introspected table metadata. */\nexport interface DbTable {\n name: string;\n columns: Record<string, DbColumn>;\n pks: string[];\n indexes: Record<string, DbIndex>;\n fks: Record<string, DbForeignKey>;\n}\n\n/** Introspected schema metadata. */\nexport interface DbSchema {\n tables: Record<string, DbTable>;\n}\n\n/**\n * PostgreSQL implementation of schema introspection.\n */\nexport class PostgresIntrospector implements DatabaseIntrospector {\n static readonly BRAND = 'tango.migrations.postgres_introspector' as const;\n readonly __tangoBrand: typeof PostgresIntrospector.BRAND = PostgresIntrospector.BRAND;\n\n /**\n * Narrow an unknown value to the PostgreSQL schema introspector.\n */\n static isPostgresIntrospector(value: unknown): value is PostgresIntrospector {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === PostgresIntrospector.BRAND\n );\n }\n\n /**\n * Read table and column metadata from PostgreSQL system catalogs.\n */\n async introspect(client: DBClient): Promise<DbSchema> {\n const schema: DbSchema = { tables: {} };\n\n const tablesRes = await client.query<{ tbl_oid: string; table: string }>(`\n SELECT c.oid AS tbl_oid, c.relname AS table\n FROM pg_class c\n JOIN pg_namespace n ON n.oid = c.relnamespace\n WHERE c.relkind = 'r' AND n.nspname NOT IN ('pg_catalog','information_schema')\n `);\n\n await Promise.all(\n tablesRes.rows.map(async (tableRow) => {\n const table = tableRow.table as string;\n\n const colsRes = await client.query<{\n name: string;\n type: string;\n not_null: boolean;\n default_expr: string | null;\n }>(`\n SELECT a.attname AS name,\n pg_catalog.format_type(a.atttypid,a.atttypmod) AS type,\n a.attnotnull AS not_null,\n pg_get_expr(ad.adbin, ad.adrelid) AS default_expr\n FROM pg_attribute a\n LEFT JOIN pg_attrdef ad ON ad.adrelid = a.attrelid AND ad.adnum = a.attnum\n WHERE a.attrelid = '${tableRow.tbl_oid}'::oid AND a.attnum > 0 AND NOT a.attisdropped\n ORDER BY a.attnum\n `);\n\n const pkRes = await client.query<{ col: string }>(`\n SELECT a.attname AS col\n FROM pg_index i\n JOIN pg_attribute a ON a.attrelid = i.indrelid AND a.attnum = ANY(i.indkey)\n WHERE i.indrelid = '${tableRow.tbl_oid}'::oid AND i.indisprimary\n `);\n const pks = pkRes.rows.map((pkRow) => pkRow.col as string);\n\n const idxRes = await client.query<{\n name: string;\n unique: boolean;\n where_clause: string | null;\n columns: string[];\n }>(`\n SELECT\n idx.relname AS name,\n i.indisunique AS unique,\n pg_get_expr(i.indpred, i.indrelid) AS where_clause,\n ARRAY(\n SELECT a.attname\n FROM unnest(i.indkey) WITH ORDINALITY AS k(attnum, ord)\n JOIN pg_attribute a ON a.attrelid = i.indrelid AND a.attnum = k.attnum\n ORDER BY k.ord\n ) AS columns\n FROM pg_index i\n JOIN pg_class idx ON idx.oid = i.indexrelid\n LEFT JOIN pg_constraint con ON con.conindid = i.indexrelid\n WHERE i.indrelid = '${tableRow.tbl_oid}'::oid\n AND NOT i.indisprimary\n AND con.oid IS NULL\n `);\n\n const indexes = idxRes.rows.reduce<Record<string, DbIndex>>((accumulator, indexRow) => {\n const name = String(indexRow.name);\n accumulator[name] = {\n name,\n table,\n unique: !!indexRow.unique,\n columns: Array.isArray(indexRow.columns) ? indexRow.columns.map(String) : [],\n where: indexRow.where_clause ? String(indexRow.where_clause) : null,\n };\n return accumulator;\n }, {});\n\n const columns = colsRes.rows.reduce<Record<string, DbColumn>>((accumulator, columnRow) => {\n const name = columnRow.name as string;\n const isPk = pks.includes(name);\n accumulator[name] = {\n name,\n type: String(columnRow.type),\n notNull: !!columnRow.not_null,\n default: columnRow.default_expr ? String(columnRow.default_expr) : null,\n isPk,\n isUnique: false,\n };\n return accumulator;\n }, {});\n\n schema.tables[table] = {\n name: table,\n columns,\n pks,\n indexes,\n fks: {},\n };\n })\n );\n\n return schema;\n }\n}\n","import type { DBClient, DatabaseIntrospector } from './DatabaseIntrospector';\nimport { MigrationSqlSafetyAdapter } from '../internal/MigrationSqlSafetyAdapter';\n\n/** Introspected column metadata. */\nexport interface DbColumn {\n name: string;\n type: string;\n notNull: boolean;\n default: string | null;\n isPk: boolean;\n isUnique: boolean;\n}\n\n/** Introspected table metadata. */\nexport interface DbTable {\n name: string;\n columns: Record<string, DbColumn>;\n pks: string[];\n indexes: Record<string, { name: string; table: string; unique: boolean; columns: string[]; where: string | null }>;\n fks: Record<\n string,\n {\n name: string;\n table: string;\n columns: string[];\n refTable: string;\n refColumns: string[];\n onDelete: string | null;\n onUpdate: string | null;\n validated: boolean;\n }\n >;\n}\n\n/** Introspected schema metadata. */\nexport interface DbSchema {\n tables: Record<string, DbTable>;\n}\n\n/**\n * SQLite implementation of schema introspection.\n */\nexport class SqliteIntrospector implements DatabaseIntrospector {\n static readonly BRAND = 'tango.migrations.sqlite_introspector' as const;\n readonly __tangoBrand: typeof SqliteIntrospector.BRAND = SqliteIntrospector.BRAND;\n private readonly sqlSafety = new MigrationSqlSafetyAdapter('sqlite');\n\n /**\n * Narrow an unknown value to the SQLite schema introspector.\n */\n static isSqliteIntrospector(value: unknown): value is SqliteIntrospector {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === SqliteIntrospector.BRAND\n );\n }\n\n /**\n * Read table/column/index metadata from SQLite pragmas.\n */\n async introspect(client: DBClient): Promise<DbSchema> {\n const schema: DbSchema = { tables: {} };\n\n const tablesRes = await client.query<{ name: string }>(`\n SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'\n `);\n\n for (const tableRow of tablesRes.rows) {\n const table = tableRow.name as string;\n const safeTable = this.sqlSafety.table(table);\n\n const colsRes = await client.query<{\n name: string;\n pk: number;\n type: string;\n notnull: number;\n dflt_value: string | null;\n }>(`PRAGMA table_info(${safeTable})`);\n\n const columns: Record<string, DbColumn> = {};\n const pks: string[] = [];\n const indexes: Record<\n string,\n { name: string; table: string; unique: boolean; columns: string[]; where: string | null }\n > = {};\n\n for (const columnRow of colsRes.rows) {\n const name = columnRow.name as string;\n const isPk = columnRow.pk === 1;\n if (isPk) {\n pks.push(name);\n }\n\n columns[name] = {\n name,\n type: String(columnRow.type),\n notNull: columnRow.notnull === 1,\n default: columnRow.dflt_value || null,\n isPk,\n isUnique: false,\n };\n }\n\n const indexListRes = await client.query<{ name: string; unique: number }>(\n `PRAGMA index_list(${safeTable})`\n );\n for (const indexRow of indexListRes.rows) {\n const name = String(indexRow.name);\n if (name.startsWith('sqlite_autoindex_')) {\n continue;\n }\n\n const indexInfoRes = await client.query<{ name: string }>(\n `PRAGMA index_info(${this.sqlSafety.index(name)})`\n );\n const on = indexInfoRes.rows.map((infoRow) => String(infoRow.name)).filter(Boolean);\n indexes[name] = {\n name,\n table,\n columns: on,\n unique: indexRow.unique === 1,\n where: null,\n };\n }\n\n schema.tables[table] = {\n name: table,\n columns,\n pks,\n indexes,\n fks: {},\n };\n }\n\n return schema;\n }\n}\n"],"mappings":";;;;;AAkDA,IAAa,uBAAb,MAAa,qBAAqD;CAC9D,OAAgB,QAAQ;CACxB,eAA2D,qBAAqB;;;;CAKhF,OAAO,uBAAuB,OAA+C;EACzE,OACI,OAAO,UAAU,YACjB,UAAU,QACT,MAAqC,iBAAiB,qBAAqB;CAEpF;;;;CAKA,MAAM,WAAW,QAAqC;EAClD,MAAM,SAAmB,EAAE,QAAQ,CAAC,EAAE;EAEtC,MAAM,YAAY,MAAM,OAAO,MAA0C;;;;;KAK5E;EAE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and curated flat exports for TS-native ergonomics.
4
- */
5
- export * as contracts from './contracts/index';
6
- export * as ops from './ops/index';
7
- export * as runtime from './runtime/index';
8
- export type { Builder, ColumnSpec, ColumnType, DeleteReferentialAction, UpdateReferentialAction, } from './contracts/index';
9
- export { OpBuilder, op, applyFieldType } from './ops/index';
10
- export { CollectingBuilder } from './runtime/index';
1
+ import { t as Builder } from "../Builder-y8vj7XXN.js";
2
+ import { _ as ColumnType, g as DeleteReferentialAction, h as UpdateReferentialAction, m as ColumnSpec } from "../MigrationOperation-qpdhPEs9.js";
3
+ import { a as OpBuilder, i as index_d_exports$1, n as index_d_exports$2, o as applyFieldType, r as CollectingBuilder, s as index_d_exports } from "../index-CzpjLzoS.js";
4
+ export { type Builder, CollectingBuilder, type ColumnSpec, type ColumnType, type DeleteReferentialAction, OpBuilder, OpBuilder as op, type UpdateReferentialAction, applyFieldType, index_d_exports as contracts, index_d_exports$1 as ops, index_d_exports$2 as runtime };
@@ -1,6 +1,3 @@
1
- import { CollectingBuilder } from "../CollectingBuilder--4fqDQdE.js";
2
- import "../InternalOperationKind-Bt6Weuon.js";
3
- import "../InternalColumnType-G9zV9StN.js";
4
- import { OpBuilder, applyFieldType, contracts_exports, ops_exports, runtime_exports } from "../builder-xJ-Bq2pk.js";
5
-
6
- export { CollectingBuilder, OpBuilder, applyFieldType, contracts_exports as contracts, OpBuilder as op, ops_exports as ops, runtime_exports as runtime };
1
+ import { a as applyFieldType, i as OpBuilder, n as runtime_exports, o as contracts_exports, r as ops_exports } from "../builder-BSepa_PF.js";
2
+ import { t as CollectingBuilder } from "../CollectingBuilder-BIfAKs_x.js";
3
+ export { CollectingBuilder, OpBuilder, OpBuilder as op, applyFieldType, contracts_exports as contracts, ops_exports as ops, runtime_exports as runtime };
@@ -1,13 +1,14 @@
1
- import { __export } from "./chunk-BkvOhyD0.js";
2
- import { CollectingBuilder } from "./CollectingBuilder--4fqDQdE.js";
3
- import { InternalOperationKind } from "./InternalOperationKind-Bt6Weuon.js";
4
- import { InternalColumnType } from "./InternalColumnType-G9zV9StN.js";
5
-
1
+ import { t as __exportAll } from "./chunk-D7D4PA-g.js";
2
+ import { t as InternalColumnType } from "./InternalColumnType-Dzs9T6a6.js";
3
+ import { t as InternalOperationKind } from "./InternalOperationKind-M4a4H9OZ.js";
4
+ import { t as CollectingBuilder } from "./CollectingBuilder-BIfAKs_x.js";
6
5
  //#region src/builder/contracts/index.ts
7
- var contracts_exports = {};
8
-
6
+ var contracts_exports = /* @__PURE__ */ __exportAll({});
9
7
  //#endregion
10
8
  //#region src/builder/ops/OpBuilder.ts
9
+ /**
10
+ * Fluent builder for column specifications used by table operations.
11
+ */
11
12
  var ColumnBuilder = class ColumnBuilder {
12
13
  static BRAND = "tango.migrations.column_builder";
13
14
  __tangoBrand = ColumnBuilder.BRAND;
@@ -97,15 +98,20 @@ var ColumnBuilder = class ColumnBuilder {
97
98
  return this.spec;
98
99
  }
99
100
  };
101
+ /**
102
+ * Static factory for migration operations.
103
+ */
100
104
  var OpBuilder = class OpBuilder {
101
105
  static BRAND = "tango.migrations.op_builder";
102
106
  static index = {
107
+ /** Build an index create operation. */
103
108
  create(p) {
104
109
  return {
105
110
  kind: InternalOperationKind.INDEX_CREATE,
106
111
  ...p
107
112
  };
108
113
  },
114
+ /** Build an index drop operation. */
109
115
  drop(p) {
110
116
  return {
111
117
  kind: InternalOperationKind.INDEX_DROP,
@@ -113,7 +119,7 @@ var OpBuilder = class OpBuilder {
113
119
  };
114
120
  }
115
121
  };
116
- static customOperations = new Map();
122
+ static customOperations = /* @__PURE__ */ new Map();
117
123
  __tangoBrand = OpBuilder.BRAND;
118
124
  /**
119
125
  * Narrow an unknown value to the shared migration operation builder type.
@@ -217,6 +223,9 @@ var OpBuilder = class OpBuilder {
217
223
  return this.customOperations.get(name);
218
224
  }
219
225
  };
226
+ /**
227
+ * Apply a domain field type to a column builder.
228
+ */
220
229
  function applyFieldType(builder, fieldType) {
221
230
  switch (fieldType) {
222
231
  case InternalColumnType.SERIAL: return builder.serial();
@@ -227,31 +236,22 @@ function applyFieldType(builder, fieldType) {
227
236
  case InternalColumnType.TIMESTAMPTZ: return builder.timestamptz();
228
237
  case InternalColumnType.JSONB: return builder.jsonb();
229
238
  case InternalColumnType.UUID: return builder.uuid();
230
- default: {
231
- const exhaustive = fieldType;
232
- throw new Error(`Unsupported field type: ${exhaustive}`);
233
- }
239
+ default: throw new Error(`Unsupported field type: ${fieldType}`);
234
240
  }
235
241
  }
236
-
237
242
  //#endregion
238
243
  //#region src/builder/ops/index.ts
239
- var ops_exports = {};
240
- __export(ops_exports, {
244
+ var ops_exports = /* @__PURE__ */ __exportAll({
241
245
  OpBuilder: () => OpBuilder,
242
246
  applyFieldType: () => applyFieldType,
243
247
  op: () => OpBuilder
244
248
  });
245
-
246
249
  //#endregion
247
250
  //#region src/builder/runtime/index.ts
248
- var runtime_exports = {};
249
- __export(runtime_exports, { CollectingBuilder: () => CollectingBuilder });
250
-
251
+ var runtime_exports = /* @__PURE__ */ __exportAll({ CollectingBuilder: () => CollectingBuilder });
251
252
  //#endregion
252
253
  //#region src/builder/index.ts
253
- var builder_exports = {};
254
- __export(builder_exports, {
254
+ var builder_exports = /* @__PURE__ */ __exportAll({
255
255
  CollectingBuilder: () => CollectingBuilder,
256
256
  OpBuilder: () => OpBuilder,
257
257
  applyFieldType: () => applyFieldType,
@@ -260,7 +260,7 @@ __export(builder_exports, {
260
260
  ops: () => ops_exports,
261
261
  runtime: () => runtime_exports
262
262
  });
263
-
264
263
  //#endregion
265
- export { OpBuilder, applyFieldType, builder_exports, contracts_exports, ops_exports, runtime_exports };
266
- //# sourceMappingURL=builder-xJ-Bq2pk.js.map
264
+ export { applyFieldType as a, OpBuilder as i, runtime_exports as n, contracts_exports as o, ops_exports as r, builder_exports as t };
265
+
266
+ //# sourceMappingURL=builder-BSepa_PF.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder-BSepa_PF.js","names":["exhaustive"],"sources":["../src/builder/contracts/index.ts","../src/builder/ops/OpBuilder.ts","../src/builder/ops/index.ts","../src/builder/runtime/index.ts","../src/builder/index.ts"],"sourcesContent":["/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\n\nexport type { Builder } from './Builder';\nexport type { ColumnSpec } from './ColumnSpec';\nexport type { ColumnType } from './ColumnType';\nexport type { DeleteReferentialAction } from './DeleteReferentialAction';\nexport type { UpdateReferentialAction } from './UpdateReferentialAction';\n","import type { TrustedSqlFragment } from '@danceroutine/tango-core';\nimport type {\n CustomMigrationOperation,\n ForeignKeyCreate,\n ForeignKeyDrop,\n ForeignKeyValidate,\n IndexCreate,\n IndexDrop,\n TableCreate,\n TableDrop,\n ColumnAdd,\n ColumnDrop,\n ColumnAlter,\n ColumnRename,\n} from '../../domain/MigrationOperation';\nimport type { ColumnSpec } from '../contracts/ColumnSpec';\nimport type { ColumnType } from '../contracts/ColumnType';\nimport { InternalColumnType } from '../../domain/internal/InternalColumnType';\nimport type { DeleteReferentialAction } from '../contracts/DeleteReferentialAction';\nimport type { UpdateReferentialAction } from '../contracts/UpdateReferentialAction';\nimport { InternalOperationKind } from '../../domain/internal/InternalOperationKind';\n\n/**\n * Fluent builder for column specifications used by table operations.\n */\nclass ColumnBuilder {\n static readonly BRAND = 'tango.migrations.column_builder' as const;\n readonly __tangoBrand: typeof ColumnBuilder.BRAND = ColumnBuilder.BRAND;\n private spec: Partial<ColumnSpec> = {};\n\n constructor(name: string) {\n this.spec.name = name;\n }\n\n static isColumnBuilder(value: unknown): value is ColumnBuilder {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === ColumnBuilder.BRAND\n );\n }\n\n /** Set column type to serial/auto-increment. */\n serial(): ColumnBuilder {\n this.spec.type = InternalColumnType.SERIAL;\n return this;\n }\n /** Set column type to integer. */\n int(): ColumnBuilder {\n this.spec.type = InternalColumnType.INT;\n return this;\n }\n /** Set column type to bigint. */\n bigint(): ColumnBuilder {\n this.spec.type = InternalColumnType.BIGINT;\n return this;\n }\n /** Set column type to text. */\n text(): ColumnBuilder {\n this.spec.type = InternalColumnType.TEXT;\n return this;\n }\n /** Set column type to boolean. */\n bool(): ColumnBuilder {\n this.spec.type = InternalColumnType.BOOL;\n return this;\n }\n /** Set column type to timestamptz. */\n timestamptz(): ColumnBuilder {\n this.spec.type = InternalColumnType.TIMESTAMPTZ;\n return this;\n }\n /** Set column type to JSONB. */\n jsonb(): ColumnBuilder {\n this.spec.type = InternalColumnType.JSONB;\n return this;\n }\n /** Set column type to UUID. */\n uuid(): ColumnBuilder {\n this.spec.type = InternalColumnType.UUID;\n return this;\n }\n\n /** Mark column as NOT NULL. */\n notNull(): ColumnBuilder {\n this.spec.notNull = true;\n return this;\n }\n /** Set default to current timestamp. */\n defaultNow(): ColumnBuilder {\n this.spec.default = { now: true };\n return this;\n }\n /** Set reviewed raw SQL default expression. */\n default(v: TrustedSqlFragment | null): ColumnBuilder {\n this.spec.default = v;\n return this;\n }\n /** Mark column as part of primary key. */\n primaryKey(): ColumnBuilder {\n this.spec.primaryKey = true;\n return this;\n }\n /** Mark column as unique. */\n unique(): ColumnBuilder {\n this.spec.unique = true;\n return this;\n }\n /** Configure foreign key reference metadata. */\n references(\n table: string,\n column: string,\n opts?: {\n onDelete?: DeleteReferentialAction;\n onUpdate?: UpdateReferentialAction;\n }\n ): ColumnBuilder {\n this.spec.references = {\n table,\n column,\n onDelete: opts?.onDelete,\n onUpdate: opts?.onUpdate,\n };\n return this;\n }\n\n _done(): ColumnSpec {\n return this.spec as ColumnSpec;\n }\n}\n\ntype TableOperationBuilder = {\n create(def: (cols: { add: (name: string, cb: (b: ColumnBuilder) => ColumnBuilder) => void }) => void): TableCreate;\n drop(opts?: { cascade?: boolean }): TableDrop;\n addColumn(name: string, cb: (b: ColumnBuilder) => ColumnBuilder): ColumnAdd;\n dropColumn(name: string): ColumnDrop;\n alterColumn(name: string, to: Partial<ColumnSpec>): ColumnAlter;\n renameColumn(from: string, to: string): ColumnRename;\n};\n\n/**\n * Static factory for migration operations.\n */\nexport class OpBuilder {\n static readonly BRAND = 'tango.migrations.op_builder' as const;\n static index = {\n /** Build an index create operation. */\n create(p: {\n name: string;\n table: string;\n on: string[];\n unique?: boolean;\n where?: TrustedSqlFragment;\n concurrently?: boolean;\n }): IndexCreate {\n return { kind: InternalOperationKind.INDEX_CREATE, ...p };\n },\n /** Build an index drop operation. */\n drop(p: { name: string; table: string; concurrently?: boolean }): IndexDrop {\n return { kind: InternalOperationKind.INDEX_DROP, ...p };\n },\n };\n private static customOperations = new Map<string, (args: Record<string, unknown>) => CustomMigrationOperation>();\n readonly __tangoBrand: typeof OpBuilder.BRAND = OpBuilder.BRAND;\n\n /**\n * Narrow an unknown value to the shared migration operation builder type.\n */\n static isOpBuilder(value: unknown): value is OpBuilder {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === OpBuilder.BRAND\n );\n }\n\n /**\n * Build table-scoped migration operations.\n */\n static table(table: string): TableOperationBuilder {\n return {\n create(\n def: (cols: { add: (name: string, cb: (b: ColumnBuilder) => ColumnBuilder) => void }) => void\n ): TableCreate {\n const columns: ColumnSpec[] = [];\n def({\n add(name, cb) {\n columns.push(cb(new ColumnBuilder(name))._done());\n },\n });\n return { kind: InternalOperationKind.TABLE_CREATE, table, columns };\n },\n drop(opts?: { cascade?: boolean }): TableDrop {\n return { kind: InternalOperationKind.TABLE_DROP, table, cascade: opts?.cascade };\n },\n addColumn(name: string, cb: (b: ColumnBuilder) => ColumnBuilder): ColumnAdd {\n return { kind: InternalOperationKind.COLUMN_ADD, table, column: cb(new ColumnBuilder(name))._done() };\n },\n dropColumn(name: string): ColumnDrop {\n return { kind: InternalOperationKind.COLUMN_DROP, table, column: name };\n },\n alterColumn(name: string, to: Partial<ColumnSpec>): ColumnAlter {\n return { kind: InternalOperationKind.COLUMN_ALTER, table, column: name, to };\n },\n renameColumn(from: string, to: string): ColumnRename {\n return { kind: InternalOperationKind.COLUMN_RENAME, table, from, to };\n },\n };\n }\n\n /** Build a foreign key create operation. */\n static foreignKey(p: {\n table: string;\n name?: string;\n columns: string[];\n references: { table: string; columns: string[] };\n onDelete?: string;\n onUpdate?: string;\n notValid?: boolean;\n }): ForeignKeyCreate {\n return {\n kind: InternalOperationKind.FK_CREATE,\n table: p.table,\n name: p.name,\n columns: p.columns,\n refTable: p.references.table,\n refColumns: p.references.columns,\n onDelete: p.onDelete,\n onUpdate: p.onUpdate,\n notValid: p.notValid,\n };\n }\n\n /** Build a foreign key validation operation. */\n static foreignKeyValidate(p: { table: string; name: string }): ForeignKeyValidate {\n return { kind: InternalOperationKind.FK_VALIDATE, ...p };\n }\n\n /** Build a foreign key drop operation. */\n static foreignKeyDrop(p: { table: string; name: string }): ForeignKeyDrop {\n return { kind: InternalOperationKind.FK_DROP, ...p };\n }\n\n /**\n * Register a custom migration operation builder.\n */\n static registerCustomOperation<TName extends string, TArgs extends object>(\n name: TName,\n builder: (args: TArgs) => CustomMigrationOperation<TName, TArgs>\n ): void {\n this.customOperations.set(name, builder as (args: Record<string, unknown>) => CustomMigrationOperation);\n }\n\n /**\n * Resolve a previously registered custom operation builder.\n */\n static getCustomOperation<TName extends string, TArgs extends object>(\n name: TName\n ): ((args: TArgs) => CustomMigrationOperation<TName, TArgs>) | undefined {\n return this.customOperations.get(name) as ((args: TArgs) => CustomMigrationOperation<TName, TArgs>) | undefined;\n }\n}\n\n/**\n * Apply a domain field type to a column builder.\n */\nexport function applyFieldType(builder: ColumnBuilder, fieldType: ColumnType): ColumnBuilder {\n switch (fieldType) {\n case InternalColumnType.SERIAL:\n return builder.serial();\n case InternalColumnType.INT:\n return builder.int();\n case InternalColumnType.BIGINT:\n return builder.bigint();\n case InternalColumnType.TEXT:\n return builder.text();\n case InternalColumnType.BOOL:\n return builder.bool();\n case InternalColumnType.TIMESTAMPTZ:\n return builder.timestamptz();\n case InternalColumnType.JSONB:\n return builder.jsonb();\n case InternalColumnType.UUID:\n return builder.uuid();\n default: {\n const exhaustive: never = fieldType;\n throw new Error(`Unsupported field type: ${exhaustive}`);\n }\n }\n}\n","/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\n\nexport { OpBuilder, OpBuilder as op, applyFieldType } from './OpBuilder';\n","/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\n\nexport { CollectingBuilder } from './CollectingBuilder';\n","/**\n * Domain boundary barrel: exposes namespaced exports for Django-style drill-down\n * imports and curated flat exports for TS-native ergonomics.\n */\n\nexport * as contracts from './contracts/index';\nexport * as ops from './ops/index';\nexport * as runtime from './runtime/index';\n\nexport type {\n Builder,\n ColumnSpec,\n ColumnType,\n DeleteReferentialAction,\n UpdateReferentialAction,\n} from './contracts/index';\nexport { OpBuilder, op, applyFieldType } from './ops/index';\nexport { CollectingBuilder } from './runtime/index';\n"],"mappings":";;;;;;;;;;;ACyBA,IAAM,gBAAN,MAAM,cAAc;CAChB,OAAgB,QAAQ;CACxB,eAAoD,cAAc;CAClE,OAAoC,CAAC;CAErC,YAAY,MAAc;EACtB,KAAK,KAAK,OAAO;CACrB;CAEA,OAAO,gBAAgB,OAAwC;EAC3D,OACI,OAAO,UAAU,YACjB,UAAU,QACT,MAAqC,iBAAiB,cAAc;CAE7E;;CAGA,SAAwB;EACpB,KAAK,KAAK,OAAO,mBAAmB;EACpC,OAAO;CACX;;CAEA,MAAqB;EACjB,KAAK,KAAK,OAAO,mBAAmB;EACpC,OAAO;CACX;;CAEA,SAAwB;EACpB,KAAK,KAAK,OAAO,mBAAmB;EACpC,OAAO;CACX;;CAEA,OAAsB;EAClB,KAAK,KAAK,OAAO,mBAAmB;EACpC,OAAO;CACX;;CAEA,OAAsB;EAClB,KAAK,KAAK,OAAO,mBAAmB;EACpC,OAAO;CACX;;CAEA,cAA6B;EACzB,KAAK,KAAK,OAAO,mBAAmB;EACpC,OAAO;CACX;;CAEA,QAAuB;EACnB,KAAK,KAAK,OAAO,mBAAmB;EACpC,OAAO;CACX;;CAEA,OAAs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B,MACpB,OAAO,QAAQ,KAAK;EACxB,KAAK,mBAAmB,aACpB,OAAO,QAAQ,YAAY;EAC/B,KAAK,mBAAmB,OACpB,OAAO,QAAQ,MAAM;EACzB,KAAK,mBAAmB,MACpB,OAAO,QAAQ,KAAK;EACxB,SAEI,MAAM,IAAI,MAAM,2BAA2BA,WAAY;CAE/D;AACJ"}
@@ -0,0 +1,13 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
+ return target;
11
+ };
12
+ //#endregion
13
+ export { __exportAll as t };
@@ -1,17 +1,16 @@
1
- import { InternalDialect } from "./CompilerStrategy-_AiXiyjS.js";
2
- import { MigrationRunner, loadModule } from "./MigrationRunner-DomrOZIn.js";
3
- import { MigrationGenerator } from "./MigrationGenerator-B1p0jHnx.js";
4
- import { buildMigrationModelMetadataProjection, diffSchema } from "./diff-B9MhagJF.js";
5
- import { createDefaultIntrospectorStrategy } from "./IntrospectorStrategy-BEIG5GqA.js";
1
+ import { r as InternalDialect } from "./CompilerStrategy-vcZKg8qf.js";
2
+ import { n as loadModule, t as MigrationRunner } from "./MigrationRunner-B5AJel12.js";
3
+ import { t as MigrationGenerator } from "./MigrationGenerator-BmmerPXJ.js";
4
+ import { n as buildMigrationModelMetadataProjection, r as diffSchema } from "./diff-7Xw8k4vp.js";
5
+ import { n as createDefaultIntrospectorStrategy } from "./IntrospectorStrategy-BijuyIaN.js";
6
+ import { getLogger } from "@danceroutine/tango-core";
6
7
  import { access, mkdir } from "node:fs/promises";
7
- import { constants as fsConstants } from "node:fs";
8
8
  import { dirname, resolve } from "node:path";
9
- import { getLogger } from "@danceroutine/tango-core";
10
9
  import { GENERATED_RELATION_REGISTRY_DIRNAME } from "@danceroutine/tango-schema";
10
+ import { constants } from "node:fs";
11
11
  import { loadConfig } from "@danceroutine/tango-config";
12
12
  import { loadProjectModule } from "@danceroutine/tango-codegen/commands";
13
13
  import { writeRelationRegistryArtifacts } from "@danceroutine/tango-codegen/generators";
14
-
15
14
  //#region src/commands/cli.ts
16
15
  const logger = getLogger("tango.migrations");
17
16
  async function importModule(modulePath) {
@@ -21,23 +20,20 @@ async function tryLoadMigrationDefaults(configPathArg, configEnvArg) {
21
20
  const explicitConfigPath = typeof configPathArg === "string" && configPathArg.trim().length > 0;
22
21
  const resolvedPath = resolve(process.cwd(), configPathArg?.trim() || "./tango.config.ts");
23
22
  try {
24
- await access(resolvedPath, fsConstants.F_OK);
23
+ await access(resolvedPath, constants.F_OK);
25
24
  } catch (error) {
26
25
  if (explicitConfigPath) throw new Error(`Config file not found: ${resolvedPath}`, { cause: error });
27
26
  return {};
28
27
  }
29
28
  const module = await importModule(resolvedPath);
30
29
  const fileConfig = module.default ?? module;
31
- const loaded = loadConfig(() => ({
30
+ const { db, migrations } = loadConfig(() => ({
32
31
  ...fileConfig,
33
32
  ...configEnvArg ? { current: configEnvArg } : {}
34
- }));
35
- const { db, migrations } = loaded.current;
36
- const inferredDialect = db.adapter;
37
- const inferredDb = resolveDbTarget(db);
33
+ })).current;
38
34
  return {
39
- dialect: inferredDialect,
40
- db: inferredDb,
35
+ dialect: db.adapter,
36
+ db: resolveDbTarget(db),
41
37
  dir: migrations.dir,
42
38
  autoApply: migrations.autoApply
43
39
  };
@@ -45,23 +41,19 @@ async function tryLoadMigrationDefaults(configPathArg, configEnvArg) {
45
41
  function resolveDbTarget(db) {
46
42
  if (db.adapter === InternalDialect.SQLITE) return db.filename ?? db.url;
47
43
  if (db.url) return db.url;
48
- if (!db.database) return undefined;
44
+ if (!db.database) return;
49
45
  const host = db.host ?? "localhost";
50
46
  const port = db.port ?? 5432;
51
47
  const encodedUser = db.user ? encodeURIComponent(db.user) : "";
52
48
  const encodedPassword = db.password ? encodeURIComponent(db.password) : "";
53
- const userInfo = encodedUser.length > 0 ? encodedPassword.length > 0 ? `${encodedUser}:${encodedPassword}@` : `${encodedUser}@` : "";
54
- return `postgres://${userInfo}${host}:${String(port)}/${db.database}`;
49
+ return `postgres://${encodedUser.length > 0 ? encodedPassword.length > 0 ? `${encodedUser}:${encodedPassword}@` : `${encodedUser}@` : ""}${host}:${String(port)}/${db.database}`;
55
50
  }
56
51
  async function resolveCommandInputs(argv) {
57
52
  const defaults = await tryLoadMigrationDefaults(argv.config, argv.env);
58
- const resolvedDialect = argv.dialect ?? defaults.dialect ?? InternalDialect.POSTGRES;
59
- const resolvedDir = argv.dir ?? defaults.dir ?? "migrations";
60
- const resolvedDb = argv.db ?? defaults.db;
61
53
  return {
62
- dialect: resolvedDialect,
63
- dir: resolvedDir,
64
- db: resolvedDb,
54
+ dialect: argv.dialect ?? defaults.dialect ?? InternalDialect.POSTGRES,
55
+ dir: argv.dir ?? defaults.dir ?? "migrations",
56
+ db: argv.db ?? defaults.db,
65
57
  autoApply: defaults.autoApply ?? true
66
58
  };
67
59
  }
@@ -98,21 +90,18 @@ async function loadModels(modelsPath) {
98
90
  async function connectAndIntrospect(dbUrl, dialect) {
99
91
  const dbClient = await connectDbClient(dbUrl, dialect);
100
92
  try {
101
- const strategy = createDefaultIntrospectorStrategy();
102
- return await strategy.introspect(dialect, dbClient);
93
+ return await createDefaultIntrospectorStrategy().introspect(dialect, dbClient);
103
94
  } finally {
104
95
  await dbClient.close();
105
96
  }
106
97
  }
107
98
  async function connectDbClient(db, dialect) {
108
99
  if (dialect === InternalDialect.POSTGRES) {
109
- const pg = await import("pg");
110
- const client = new pg.default.Client({ connectionString: db });
100
+ const client = new (await (import("pg"))).default.Client({ connectionString: db });
111
101
  await client.connect();
112
102
  return {
113
103
  async query(sql, params) {
114
- const result = await client.query(sql, params);
115
- return { rows: result.rows };
104
+ return { rows: (await client.query(sql, params)).rows };
116
105
  },
117
106
  async close() {
118
107
  await client.end();
@@ -129,8 +118,7 @@ async function connectDbClient(db, dialect) {
129
118
  async query(sql, params) {
130
119
  const statement = connection.prepare(sql);
131
120
  const values = [...params ?? []];
132
- const isSelectLike = /^\s*(SELECT|PRAGMA|WITH)\b/i.test(sql);
133
- if (isSelectLike) return { rows: statement.all(...values) };
121
+ if (/^\s*(SELECT|PRAGMA|WITH)\b/i.test(sql)) return { rows: statement.all(...values) };
134
122
  statement.run(...values);
135
123
  return { rows: [] };
136
124
  },
@@ -148,9 +136,12 @@ async function ensureSqliteParentDirectory(filename) {
148
136
  await mkdir(directory, { recursive: true });
149
137
  }
150
138
  function normalizeSqliteFilename(db) {
151
- if (db.startsWith("sqlite://")) return db.slice("sqlite://".length);
139
+ if (db.startsWith("sqlite://")) return db.slice(9);
152
140
  return db;
153
141
  }
142
+ /**
143
+ * Register Tango's migration commands on an existing yargs parser.
144
+ */
154
145
  function registerMigrationsCommands(yargsBuilder) {
155
146
  return yargsBuilder.command("migrate", "Apply pending migrations to the database", (builder) => builder.option("dir", {
156
147
  type: "string",
@@ -190,8 +181,7 @@ function registerMigrationsCommands(yargsBuilder) {
190
181
  }
191
182
  if (!resolved.db) throw new Error("No database target provided. Pass --db or define db settings in tango.config.ts.");
192
183
  const dbClient = await connectDbClient(resolved.db, resolved.dialect);
193
- const runner = new MigrationRunner(dbClient, resolved.dialect, resolved.dir);
194
- await runner.apply(argv.to);
184
+ await new MigrationRunner(dbClient, resolved.dialect, resolved.dir).apply(argv.to);
195
185
  await dbClient.close();
196
186
  logger.info("Migrations applied successfully");
197
187
  }).command("make:migrations", "Generate migration file by comparing models to database", (builder) => builder.option("dir", {
@@ -253,8 +243,7 @@ function registerMigrationsCommands(yargsBuilder) {
253
243
  logger.info("No changes detected — models and database are in sync");
254
244
  return;
255
245
  }
256
- const generator = new MigrationGenerator();
257
- const filepath = await generator.generate({
246
+ const filepath = await new MigrationGenerator().generate({
258
247
  name: argv.name,
259
248
  operations,
260
249
  directory: resolved.dir
@@ -287,11 +276,10 @@ function registerMigrationsCommands(yargsBuilder) {
287
276
  config: argv.config,
288
277
  env: argv.env
289
278
  });
290
- const runner = new MigrationRunner({
279
+ const output = await new MigrationRunner({
291
280
  query: async () => ({ rows: [] }),
292
281
  close: async () => {}
293
- }, resolved.dialect, resolved.dir);
294
- const output = await runner.plan();
282
+ }, resolved.dialect, resolved.dir).plan();
295
283
  logger.info(output);
296
284
  }).command("status", "Show applied/pending status of all migrations", (builder) => builder.option("dir", {
297
285
  type: "string",
@@ -324,17 +312,16 @@ function registerMigrationsCommands(yargsBuilder) {
324
312
  });
325
313
  if (!resolved.db) throw new Error("No database target provided. Pass --db or define db settings in tango.config.ts.");
326
314
  const dbClient = await connectDbClient(resolved.db, resolved.dialect);
327
- const runner = new MigrationRunner(dbClient, resolved.dialect, resolved.dir);
328
- const statuses = await runner.status();
315
+ const statuses = await new MigrationRunner(dbClient, resolved.dialect, resolved.dir).status();
329
316
  if (statuses.length === 0) logger.info("No migrations found");
330
- else statuses.forEach((statusItem) => {
317
+ else statuses.forEach((statusItem) => {
331
318
  const marker = statusItem.applied ? "[x]" : "[ ]";
332
319
  logger.info(` ${marker} ${statusItem.id}`);
333
320
  });
334
321
  await dbClient.close();
335
322
  });
336
323
  }
337
-
338
324
  //#endregion
339
- export { registerMigrationsCommands };
340
- //# sourceMappingURL=cli-7j3R1Y1r.js.map
325
+ export { registerMigrationsCommands as t };
326
+
327
+ //# sourceMappingURL=cli-e8I1-dab.js.map