@noormdev/sdk 1.0.0-alpha.15 → 1.0.0-alpha.17

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/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { processFile, DtReader, isTemplate, FORMAT_VERSION, DT_EXTENSIONS, encryptWithPassphrase, ENCODED_TYPES, GZIP_THRESHOLD, GZIP_RATIO_THRESHOLD } from './chunk-BTXUEWYQ.js';
2
- import { NOORM_TABLES, initializeVault, getVaultStatus, setVaultSecret, getVaultSecret, getAllVaultSecrets, listVaultSecretKeys, deleteVaultSecret, vaultSecretExists, getVaultKey, encryptVaultKey } from './chunk-ZRZ7AECF.js';
2
+ import { initializeVault, getVaultStatus, setVaultSecret, getVaultSecret, getAllVaultSecrets, listVaultSecretKeys, deleteVaultSecret, vaultSecretExists, getVaultKey, noormDb, getNoormTables, encryptVaultKey } from './chunk-LJDHQEWW.js';
3
3
  import { observer } from './chunk-4HW4CS2C.js';
4
4
  import { constants, existsSync, readFileSync, mkdirSync, writeFileSync, createWriteStream } from 'fs';
5
5
  import path, { join, dirname } from 'path';
@@ -1815,7 +1815,7 @@ async function getDialectFactory(dialect) {
1815
1815
  case "mysql":
1816
1816
  return (await import('./mysql-C2DR4TF7.js')).createMysqlConnection;
1817
1817
  case "mssql":
1818
- return (await import('./mssql-T4M7OGEC.js')).createMssqlConnection;
1818
+ return (await import('./mssql-7VB7EHRX.js')).createMssqlConnection;
1819
1819
  default:
1820
1820
  throw new Error(`Unsupported dialect: ${dialect}`);
1821
1821
  }
@@ -1861,6 +1861,11 @@ async function createConnection(config, configName = "__default__") {
1861
1861
  if (msg.includes("authentication")) return false;
1862
1862
  if (msg.includes("password")) return false;
1863
1863
  if (msg.includes("missing driver")) return false;
1864
+ if (msg.includes("login failed")) return false;
1865
+ if (msg.includes("failed to open")) return false;
1866
+ if (msg.includes("does not exist")) return false;
1867
+ if (msg.includes("unknown database")) return false;
1868
+ if (msg.includes("access denied")) return false;
1864
1869
  return msg.includes("econnrefused") || msg.includes("etimedout") || msg.includes("too many connections") || msg.includes("connection reset");
1865
1870
  }
1866
1871
  }
@@ -1884,7 +1889,7 @@ async function createConnection(config, configName = "__default__") {
1884
1889
  destroy: wrappedDestroy
1885
1890
  };
1886
1891
  observer.emit("connection:open", { configName, dialect: config.dialect });
1887
- await waitForIdentityToLoad(trackedConn.db);
1892
+ await waitForIdentityToLoad(trackedConn.db, config.dialect);
1888
1893
  return trackedConn;
1889
1894
  }
1890
1895
  var SYSTEM_DATABASES = {
@@ -1915,7 +1920,7 @@ async function testConnection(config, options = {}) {
1915
1920
  // src/core/version/types.ts
1916
1921
  var CURRENT_VERSIONS = Object.freeze({
1917
1922
  /** Database tracking tables schema version */
1918
- schema: 1,
1923
+ schema: 2,
1919
1924
  /** State file (state.enc) schema version */
1920
1925
  state: 1,
1921
1926
  /** Settings file (settings.yml) schema version */
@@ -2017,6 +2022,171 @@ var v1 = {
2017
2022
  await db.schema.dropTable("__noorm_version__").execute();
2018
2023
  }
2019
2024
  };
2025
+ var TABLE_MAP = [
2026
+ { old: "__noorm_version__", new: "version" },
2027
+ { old: "__noorm_change__", new: "change" },
2028
+ { old: "__noorm_executions__", new: "executions" },
2029
+ { old: "__noorm_lock__", new: "lock" },
2030
+ { old: "__noorm_identities__", new: "identities" },
2031
+ { old: "__noorm_vault__", new: "vault" }
2032
+ ];
2033
+ var INDEXES = [
2034
+ { name: "idx_executions_change_id", table: "executions", columns: ["change_id"] },
2035
+ { name: "idx_change_name_config", table: "change", columns: ["name", "config_name"] },
2036
+ { name: "idx_vault_secret_key", table: "vault", columns: ["secret_key"] }
2037
+ ];
2038
+ var v2 = {
2039
+ version: 2,
2040
+ description: "Move tracking tables to noorm schema",
2041
+ async up(db, dialect) {
2042
+ if (dialect === "sqlite" || dialect === "mysql") return;
2043
+ await db.transaction().execute(async (trx) => {
2044
+ if (dialect === "postgres") {
2045
+ await sql`CREATE SCHEMA IF NOT EXISTS noorm`.execute(trx);
2046
+ } else {
2047
+ await sql`IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'noorm') EXEC('CREATE SCHEMA noorm')`.execute(trx);
2048
+ }
2049
+ if (dialect === "postgres") {
2050
+ const { rows } = await sql`
2051
+ SELECT constraint_name
2052
+ FROM information_schema.table_constraints
2053
+ WHERE table_name = '__noorm_executions__'
2054
+ AND constraint_type = 'FOREIGN KEY'
2055
+ `.execute(trx);
2056
+ for (const row of rows) {
2057
+ await sql`ALTER TABLE __noorm_executions__ DROP CONSTRAINT ${sql.ref(row.constraint_name)}`.execute(trx);
2058
+ }
2059
+ } else {
2060
+ const { rows } = await sql`
2061
+ SELECT fk.name AS fk_name
2062
+ FROM sys.foreign_keys fk
2063
+ JOIN sys.tables t ON fk.parent_object_id = t.object_id
2064
+ WHERE t.name = '__noorm_executions__'
2065
+ `.execute(trx);
2066
+ for (const row of rows) {
2067
+ await sql`ALTER TABLE __noorm_executions__ DROP CONSTRAINT ${sql.ref(row.fk_name)}`.execute(trx);
2068
+ }
2069
+ }
2070
+ if (dialect === "postgres") {
2071
+ for (const idx of INDEXES) {
2072
+ await sql`DROP INDEX IF EXISTS ${sql.ref(idx.name)}`.execute(trx);
2073
+ }
2074
+ } else {
2075
+ const prefixedTables = {
2076
+ executions: "__noorm_executions__",
2077
+ change: "__noorm_change__",
2078
+ vault: "__noorm_vault__"
2079
+ };
2080
+ for (const idx of INDEXES) {
2081
+ const tableName = prefixedTables[idx.table];
2082
+ await sql`
2083
+ IF EXISTS (SELECT 1 FROM sys.indexes WHERE name = ${idx.name})
2084
+ DROP INDEX ${sql.ref(idx.name)} ON ${sql.table(tableName)}
2085
+ `.execute(trx);
2086
+ }
2087
+ }
2088
+ for (const t of TABLE_MAP) {
2089
+ if (dialect === "postgres") {
2090
+ await sql`ALTER TABLE ${sql.table(t.old)} SET SCHEMA noorm`.execute(trx);
2091
+ } else {
2092
+ await sql`ALTER SCHEMA noorm TRANSFER ${sql.ref(`dbo.${t.old}`)}`.execute(trx);
2093
+ }
2094
+ }
2095
+ for (const t of TABLE_MAP) {
2096
+ if (dialect === "postgres") {
2097
+ await sql`ALTER TABLE ${sql.table(`noorm.${t.old}`)} RENAME TO ${sql.ref(t.new)}`.execute(trx);
2098
+ } else {
2099
+ await sql`EXEC sp_rename ${sql.raw(`'noorm.${t.old}'`)}, ${sql.raw(`'${t.new}'`)}`.execute(trx);
2100
+ }
2101
+ }
2102
+ await sql`
2103
+ ALTER TABLE ${sql.table("noorm.executions")}
2104
+ ADD CONSTRAINT fk_executions_change_id
2105
+ FOREIGN KEY (change_id) REFERENCES ${sql.table("noorm.change")}(id)
2106
+ ON DELETE CASCADE
2107
+ `.execute(trx);
2108
+ for (const idx of INDEXES) {
2109
+ const cols = idx.columns.join(", ");
2110
+ await sql`CREATE INDEX ${sql.ref(idx.name)} ON ${sql.table(`noorm.${idx.table}`)} (${sql.raw(cols)})`.execute(trx);
2111
+ }
2112
+ });
2113
+ },
2114
+ async down(db, dialect) {
2115
+ if (dialect === "sqlite" || dialect === "mysql") return;
2116
+ await db.transaction().execute(async (trx) => {
2117
+ if (dialect === "postgres") {
2118
+ const { rows } = await sql`
2119
+ SELECT constraint_name
2120
+ FROM information_schema.table_constraints
2121
+ WHERE table_schema = 'noorm'
2122
+ AND table_name = 'executions'
2123
+ AND constraint_type = 'FOREIGN KEY'
2124
+ `.execute(trx);
2125
+ for (const row of rows) {
2126
+ await sql`ALTER TABLE ${sql.table("noorm.executions")} DROP CONSTRAINT ${sql.ref(row.constraint_name)}`.execute(trx);
2127
+ }
2128
+ } else {
2129
+ const { rows } = await sql`
2130
+ SELECT fk.name AS fk_name
2131
+ FROM sys.foreign_keys fk
2132
+ JOIN sys.tables t ON fk.parent_object_id = t.object_id
2133
+ JOIN sys.schemas s ON t.schema_id = s.schema_id
2134
+ WHERE t.name = 'executions' AND s.name = 'noorm'
2135
+ `.execute(trx);
2136
+ for (const row of rows) {
2137
+ await sql`ALTER TABLE ${sql.table("noorm.executions")} DROP CONSTRAINT ${sql.ref(row.fk_name)}`.execute(trx);
2138
+ }
2139
+ }
2140
+ if (dialect === "postgres") {
2141
+ for (const idx of INDEXES) {
2142
+ await sql`DROP INDEX IF EXISTS ${sql.ref(`noorm.${idx.name}`)}`.execute(trx);
2143
+ }
2144
+ } else {
2145
+ for (const idx of INDEXES) {
2146
+ await sql`
2147
+ IF EXISTS (SELECT 1 FROM sys.indexes WHERE name = ${idx.name})
2148
+ DROP INDEX ${sql.ref(idx.name)} ON ${sql.table(`noorm.${idx.table}`)}
2149
+ `.execute(trx);
2150
+ }
2151
+ }
2152
+ for (const t of TABLE_MAP) {
2153
+ if (dialect === "postgres") {
2154
+ await sql`ALTER TABLE ${sql.table(`noorm.${t.new}`)} RENAME TO ${sql.ref(t.old)}`.execute(trx);
2155
+ } else {
2156
+ await sql`EXEC sp_rename ${sql.raw(`'noorm.${t.new}'`)}, ${sql.raw(`'${t.old}'`)}`.execute(trx);
2157
+ }
2158
+ }
2159
+ for (const t of TABLE_MAP) {
2160
+ if (dialect === "postgres") {
2161
+ await sql`ALTER TABLE ${sql.table(`noorm.${t.old}`)} SET SCHEMA public`.execute(trx);
2162
+ } else {
2163
+ await sql`ALTER SCHEMA dbo TRANSFER ${sql.ref(`noorm.${t.old}`)}`.execute(trx);
2164
+ }
2165
+ }
2166
+ await sql`
2167
+ ALTER TABLE __noorm_executions__
2168
+ ADD CONSTRAINT fk_executions_change_id
2169
+ FOREIGN KEY (change_id) REFERENCES __noorm_change__(id)
2170
+ ON DELETE CASCADE
2171
+ `.execute(trx);
2172
+ for (const idx of INDEXES) {
2173
+ const prefixedTables = {
2174
+ executions: "__noorm_executions__",
2175
+ change: "__noorm_change__",
2176
+ vault: "__noorm_vault__"
2177
+ };
2178
+ const tableName = prefixedTables[idx.table];
2179
+ const cols = idx.columns.join(", ");
2180
+ await sql`CREATE INDEX ${sql.ref(idx.name)} ON ${sql.table(tableName)} (${sql.raw(cols)})`.execute(trx);
2181
+ }
2182
+ if (dialect === "postgres") {
2183
+ await sql`DROP SCHEMA IF EXISTS noorm`.execute(trx);
2184
+ } else {
2185
+ await sql`IF EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'noorm') DROP SCHEMA noorm`.execute(trx);
2186
+ }
2187
+ });
2188
+ }
2189
+ };
2020
2190
 
2021
2191
  // src/core/update/checker.ts
2022
2192
  function getCurrentVersion() {
@@ -2024,26 +2194,43 @@ function getCurrentVersion() {
2024
2194
  }
2025
2195
 
2026
2196
  // src/core/version/schema/index.ts
2027
- var MIGRATIONS = [v1];
2028
- async function tablesExist(db) {
2029
- const [result, err] = await attempt(async () => {
2030
- await sql`SELECT 1 FROM __noorm_version__ LIMIT 1`.execute(db);
2197
+ var MIGRATIONS = [v1, v2];
2198
+ async function tablesExist(db, dialect) {
2199
+ const [legacyResult] = await attempt(async () => {
2200
+ await db.selectFrom("__noorm_version__").select("id").limit(1).executeTakeFirst();
2031
2201
  return true;
2032
2202
  });
2033
- if (err) return false;
2034
- return result;
2203
+ if (legacyResult) return true;
2204
+ if (dialect === "postgres" || dialect === "mssql") {
2205
+ const ndb = noormDb(db, dialect);
2206
+ const tables = getNoormTables(dialect);
2207
+ const [schemaResult] = await attempt(async () => {
2208
+ await ndb.selectFrom(tables.version).select("id").limit(1).executeTakeFirst();
2209
+ return true;
2210
+ });
2211
+ if (schemaResult) return true;
2212
+ }
2213
+ return false;
2035
2214
  }
2036
- async function getSchemaVersion(db) {
2037
- const exists = await tablesExist(db);
2215
+ async function getSchemaVersion(db, dialect) {
2216
+ const exists = await tablesExist(db, dialect);
2038
2217
  if (!exists) return 0;
2039
- const [result, err] = await attempt(async () => {
2218
+ const [legacyResult] = await attempt(async () => {
2040
2219
  return db.selectFrom("__noorm_version__").select("noorm_version").orderBy("id", "desc").limit(1).executeTakeFirst();
2041
2220
  });
2042
- if (err) return 0;
2043
- return result?.noorm_version ?? 0;
2221
+ if (legacyResult) return legacyResult.noorm_version ?? 0;
2222
+ if (dialect === "postgres" || dialect === "mssql") {
2223
+ const ndb = noormDb(db, dialect);
2224
+ const tables = getNoormTables(dialect);
2225
+ const [schemaResult] = await attempt(async () => {
2226
+ return ndb.selectFrom(tables.version).select("noorm_version").orderBy("id", "desc").limit(1).executeTakeFirst();
2227
+ });
2228
+ if (schemaResult) return schemaResult.noorm_version ?? 0;
2229
+ }
2230
+ return 0;
2044
2231
  }
2045
- async function checkSchemaVersion(db) {
2046
- const current = await getSchemaVersion(db);
2232
+ async function checkSchemaVersion(db, dialect) {
2233
+ const current = await getSchemaVersion(db, dialect);
2047
2234
  const expected = CURRENT_VERSIONS.schema;
2048
2235
  observer.emit("version:schema:checking", { current });
2049
2236
  return {
@@ -2065,7 +2252,9 @@ async function bootstrapSchema(db, dialect, options) {
2065
2252
  throw new MigrationError("schema", migration.version, err);
2066
2253
  }
2067
2254
  }
2068
- await db.insertInto("__noorm_version__").values({
2255
+ const ndb = noormDb(db, dialect);
2256
+ const tables = getNoormTables(dialect);
2257
+ await ndb.insertInto(tables.version).values({
2069
2258
  cli_version: getCurrentVersion(),
2070
2259
  noorm_version: CURRENT_VERSIONS.schema,
2071
2260
  state_version: CURRENT_VERSIONS.state,
@@ -2077,22 +2266,37 @@ async function bootstrapSchema(db, dialect, options) {
2077
2266
  to: CURRENT_VERSIONS.schema,
2078
2267
  durationMs
2079
2268
  });
2080
- await waitForIdentityToLoad(db);
2269
+ await waitForIdentityToLoad(db, dialect);
2081
2270
  }
2082
- async function getLatestVersionRecord(db) {
2083
- const exists = await tablesExist(db);
2271
+ async function getLatestVersionRecord(db, dialect) {
2272
+ const exists = await tablesExist(db, dialect);
2084
2273
  if (!exists) return null;
2085
- const [result, err] = await attempt(async () => {
2274
+ const [legacyResult] = await attempt(async () => {
2086
2275
  return db.selectFrom("__noorm_version__").select(["state_version", "settings_version"]).orderBy("id", "desc").limit(1).executeTakeFirst();
2087
2276
  });
2088
- if (err || !result) return null;
2089
- return {
2090
- stateVersion: result.state_version,
2091
- settingsVersion: result.settings_version
2092
- };
2277
+ if (legacyResult) {
2278
+ return {
2279
+ stateVersion: legacyResult.state_version,
2280
+ settingsVersion: legacyResult.settings_version
2281
+ };
2282
+ }
2283
+ if (dialect === "postgres" || dialect === "mssql") {
2284
+ const ndb = noormDb(db, dialect);
2285
+ const tables = getNoormTables(dialect);
2286
+ const [schemaResult] = await attempt(async () => {
2287
+ return ndb.selectFrom(tables.version).select(["state_version", "settings_version"]).orderBy("id", "desc").limit(1).executeTakeFirst();
2288
+ });
2289
+ if (schemaResult) {
2290
+ return {
2291
+ stateVersion: schemaResult.state_version,
2292
+ settingsVersion: schemaResult.settings_version
2293
+ };
2294
+ }
2295
+ }
2296
+ return null;
2093
2297
  }
2094
2298
  async function migrateSchema(db, dialect, options) {
2095
- const status = await checkSchemaVersion(db);
2299
+ const status = await checkSchemaVersion(db, dialect);
2096
2300
  if (status.isNewer) {
2097
2301
  observer.emit("version:mismatch", {
2098
2302
  layer: "schema",
@@ -2111,7 +2315,7 @@ async function migrateSchema(db, dialect, options) {
2111
2315
  from: status.current,
2112
2316
  to: CURRENT_VERSIONS.schema
2113
2317
  });
2114
- const existing = await getLatestVersionRecord(db);
2318
+ const existing = await getLatestVersionRecord(db, dialect);
2115
2319
  const pendingMigrations = MIGRATIONS.filter((m) => m.version > status.current);
2116
2320
  for (const migration of pendingMigrations) {
2117
2321
  const [, err] = await attempt(() => migration.up(db, dialect));
@@ -2119,7 +2323,9 @@ async function migrateSchema(db, dialect, options) {
2119
2323
  throw new MigrationError("schema", migration.version, err);
2120
2324
  }
2121
2325
  }
2122
- await db.insertInto("__noorm_version__").values({
2326
+ const ndb = noormDb(db, dialect);
2327
+ const tables = getNoormTables(dialect);
2328
+ await ndb.insertInto(tables.version).values({
2123
2329
  cli_version: getCurrentVersion(),
2124
2330
  noorm_version: CURRENT_VERSIONS.schema,
2125
2331
  state_version: existing?.stateVersion ?? CURRENT_VERSIONS.state,
@@ -2131,7 +2337,7 @@ async function migrateSchema(db, dialect, options) {
2131
2337
  to: CURRENT_VERSIONS.schema,
2132
2338
  durationMs
2133
2339
  });
2134
- await waitForIdentityToLoad(db);
2340
+ await waitForIdentityToLoad(db, dialect);
2135
2341
  }
2136
2342
  async function ensureSchemaVersion(db, dialect, options) {
2137
2343
  await migrateSchema(db, dialect);
@@ -2279,9 +2485,11 @@ addMaskedFields([
2279
2485
  ]);
2280
2486
 
2281
2487
  // src/core/identity/sync.ts
2282
- async function registerIdentity(db, identity) {
2488
+ async function registerIdentity(db, identity, dialect) {
2489
+ const ndb = noormDb(db, dialect);
2490
+ const tables = getNoormTables(dialect);
2283
2491
  const [existing, selectErr] = await attempt(
2284
- () => db.selectFrom("__noorm_identities__").select(["id"]).where("identity_hash", "=", identity.identityHash).executeTakeFirst()
2492
+ () => ndb.selectFrom(tables.identities).select(["id"]).where("identity_hash", "=", identity.identityHash).executeTakeFirst()
2285
2493
  );
2286
2494
  if (selectErr) {
2287
2495
  observer.emit("error", {
@@ -2297,7 +2505,7 @@ async function registerIdentity(db, identity) {
2297
2505
  }
2298
2506
  if (existing) {
2299
2507
  const [, updateErr] = await attempt(
2300
- () => db.updateTable("__noorm_identities__").set({ last_seen_at: /* @__PURE__ */ new Date() }).where("identity_hash", "=", identity.identityHash).execute()
2508
+ () => ndb.updateTable(tables.identities).set({ last_seen_at: /* @__PURE__ */ new Date() }).where("identity_hash", "=", identity.identityHash).execute()
2301
2509
  );
2302
2510
  if (updateErr) {
2303
2511
  observer.emit("error", {
@@ -2314,7 +2522,7 @@ async function registerIdentity(db, identity) {
2314
2522
  return { ok: true, registered: false };
2315
2523
  }
2316
2524
  const [, insertErr] = await attempt(
2317
- () => db.insertInto("__noorm_identities__").values({
2525
+ () => ndb.insertInto(tables.identities).values({
2318
2526
  identity_hash: identity.identityHash,
2319
2527
  email: identity.email,
2320
2528
  name: identity.name,
@@ -2357,11 +2565,11 @@ function resolveIdentity2(options = {}) {
2357
2565
  function getIdentityForConfig(config) {
2358
2566
  return resolveIdentity2({ configIdentity: config.identity });
2359
2567
  }
2360
- async function waitForIdentityToLoad(db) {
2568
+ async function waitForIdentityToLoad(db, dialect) {
2361
2569
  const identity = await loadExistingIdentity();
2362
2570
  if (!identity) observer.emit("identity:not-found");
2363
2571
  if (!identity) return;
2364
- const [, err] = await attempt(() => registerIdentity(db, identity));
2572
+ const [, err] = await attempt(() => registerIdentity(db, identity, dialect));
2365
2573
  if (err) observer.emit("error", {
2366
2574
  error: err,
2367
2575
  source: "identity:ensure",
@@ -2941,9 +3149,13 @@ function getExtension(filename) {
2941
3149
  }
2942
3150
  var ChangeHistory = class {
2943
3151
  #db;
3152
+ #ndb;
3153
+ #tables;
2944
3154
  #configName;
2945
- constructor(db, configName) {
3155
+ constructor(db, configName, dialect = "sqlite") {
2946
3156
  this.#db = db;
3157
+ this.#ndb = noormDb(db, dialect);
3158
+ this.#tables = getNoormTables(dialect);
2947
3159
  this.#configName = configName;
2948
3160
  }
2949
3161
  // ─────────────────────────────────────────────────────────
@@ -2960,7 +3172,7 @@ var ChangeHistory = class {
2960
3172
  */
2961
3173
  async getStatus(name) {
2962
3174
  const [record, err] = await attempt(
2963
- () => this.#db.selectFrom(NOORM_TABLES.change).select([
3175
+ () => this.#ndb.selectFrom(this.#tables.change).select([
2964
3176
  "name",
2965
3177
  "status",
2966
3178
  "executed_at",
@@ -2981,7 +3193,7 @@ var ChangeHistory = class {
2981
3193
  return null;
2982
3194
  }
2983
3195
  const [revertRecord] = await attempt(
2984
- () => this.#db.selectFrom(NOORM_TABLES.change).select(["executed_at"]).where("name", "=", name).where("change_type", "=", "change").where("direction", "=", "revert").where("status", "=", "success").where("config_name", "=", this.#configName).orderBy("id", "desc").limit(1).executeTakeFirst()
3196
+ () => this.#ndb.selectFrom(this.#tables.change).select(["executed_at"]).where("name", "=", name).where("change_type", "=", "change").where("direction", "=", "revert").where("status", "=", "success").where("config_name", "=", this.#configName).orderBy("id", "desc").limit(1).executeTakeFirst()
2985
3197
  );
2986
3198
  return {
2987
3199
  name: record.name,
@@ -3002,7 +3214,7 @@ var ChangeHistory = class {
3002
3214
  async getAllStatuses() {
3003
3215
  const statuses = /* @__PURE__ */ new Map();
3004
3216
  const [records, err] = await attempt(
3005
- () => this.#db.selectFrom(NOORM_TABLES.change).select(["id", "name", "status", "executed_at", "executed_by", "error_message"]).where("change_type", "=", "change").where("direction", "=", "change").where("config_name", "=", this.#configName).orderBy("id", "desc").execute()
3217
+ () => this.#ndb.selectFrom(this.#tables.change).select(["id", "name", "status", "executed_at", "executed_by", "error_message"]).where("change_type", "=", "change").where("direction", "=", "change").where("config_name", "=", this.#configName).orderBy("id", "desc").execute()
3006
3218
  );
3007
3219
  if (err) {
3008
3220
  observer.emit("error", {
@@ -3026,7 +3238,7 @@ var ChangeHistory = class {
3026
3238
  }
3027
3239
  }
3028
3240
  const [reverts] = await attempt(
3029
- () => this.#db.selectFrom(NOORM_TABLES.change).select(["name", "executed_at"]).where("change_type", "=", "change").where("direction", "=", "revert").where("status", "=", "success").where("config_name", "=", this.#configName).orderBy("id", "desc").execute()
3241
+ () => this.#ndb.selectFrom(this.#tables.change).select(["name", "executed_at"]).where("change_type", "=", "change").where("direction", "=", "revert").where("status", "=", "success").where("config_name", "=", this.#configName).orderBy("id", "desc").execute()
3030
3242
  );
3031
3243
  if (reverts) {
3032
3244
  const seenReverts = /* @__PURE__ */ new Set();
@@ -3056,7 +3268,7 @@ var ChangeHistory = class {
3056
3268
  return { needsRun: true, reason: "force" };
3057
3269
  }
3058
3270
  const [record, err] = await attempt(
3059
- () => this.#db.selectFrom(NOORM_TABLES.change).select(["status", "checksum"]).where("name", "=", name).where("change_type", "=", "change").where("direction", "=", "change").where("config_name", "=", this.#configName).orderBy("id", "desc").limit(1).executeTakeFirst()
3271
+ () => this.#ndb.selectFrom(this.#tables.change).select(["status", "checksum"]).where("name", "=", name).where("change_type", "=", "change").where("direction", "=", "change").where("config_name", "=", this.#configName).orderBy("id", "desc").limit(1).executeTakeFirst()
3060
3272
  );
3061
3273
  if (err) {
3062
3274
  observer.emit("error", {
@@ -3121,7 +3333,7 @@ var ChangeHistory = class {
3121
3333
  */
3122
3334
  async createOperation(data2) {
3123
3335
  const [result, err] = await attempt(
3124
- () => this.#db.insertInto(NOORM_TABLES.change).values({
3336
+ () => this.#ndb.insertInto(this.#tables.change).values({
3125
3337
  name: data2.name,
3126
3338
  change_type: "change",
3127
3339
  direction: data2.direction,
@@ -3165,7 +3377,7 @@ var ChangeHistory = class {
3165
3377
  status: "pending"
3166
3378
  }));
3167
3379
  const [, err] = await attempt(
3168
- () => this.#db.insertInto(NOORM_TABLES.executions).values(values).execute()
3380
+ () => this.#ndb.insertInto(this.#tables.executions).values(values).execute()
3169
3381
  );
3170
3382
  if (err) {
3171
3383
  const errMsg = err instanceof Error ? err.message : String(err);
@@ -3188,7 +3400,7 @@ var ChangeHistory = class {
3188
3400
  */
3189
3401
  async updateFileExecution(operationId, filepath, status, durationMs, errorMessage, skipReason) {
3190
3402
  const [result, err] = await attempt(
3191
- () => this.#db.updateTable(NOORM_TABLES.executions).set({
3403
+ () => this.#ndb.updateTable(this.#tables.executions).set({
3192
3404
  status,
3193
3405
  duration_ms: Math.round(durationMs),
3194
3406
  error_message: errorMessage ?? "",
@@ -3223,7 +3435,7 @@ var ChangeHistory = class {
3223
3435
  */
3224
3436
  async skipRemainingFiles(operationId, reason) {
3225
3437
  const [, err] = await attempt(
3226
- () => this.#db.updateTable(NOORM_TABLES.executions).set({
3438
+ () => this.#ndb.updateTable(this.#tables.executions).set({
3227
3439
  status: "skipped",
3228
3440
  skip_reason: reason
3229
3441
  }).where("change_id", "=", operationId).where("status", "=", "pending").execute()
@@ -3246,7 +3458,7 @@ var ChangeHistory = class {
3246
3458
  async finalizeOperation(operationId, status, checksum, durationMs, errorMessage) {
3247
3459
  const truncatedError = errorMessage ? errorMessage.slice(0, 2e3) : "";
3248
3460
  const [result, err] = await attempt(
3249
- () => this.#db.updateTable(NOORM_TABLES.change).set({
3461
+ () => this.#ndb.updateTable(this.#tables.change).set({
3250
3462
  status,
3251
3463
  checksum,
3252
3464
  duration_ms: Math.round(durationMs),
@@ -3287,7 +3499,7 @@ var ChangeHistory = class {
3287
3499
  */
3288
3500
  async recordReset(executedBy, reason) {
3289
3501
  const [result, err] = await attempt(
3290
- () => this.#db.insertInto(NOORM_TABLES.change).values({
3502
+ () => this.#ndb.insertInto(this.#tables.change).values({
3291
3503
  name: "__reset__",
3292
3504
  change_type: "change",
3293
3505
  direction: "change",
@@ -3317,14 +3529,14 @@ var ChangeHistory = class {
3317
3529
  */
3318
3530
  async deleteRecords(name) {
3319
3531
  const [operations, queryErr] = await attempt(
3320
- () => this.#db.selectFrom(NOORM_TABLES.change).select(["id"]).where("name", "=", name).where("change_type", "=", "change").where("config_name", "=", this.#configName).execute()
3532
+ () => this.#ndb.selectFrom(this.#tables.change).select(["id"]).where("name", "=", name).where("change_type", "=", "change").where("config_name", "=", this.#configName).execute()
3321
3533
  );
3322
3534
  if (queryErr || !operations || operations.length === 0) {
3323
3535
  return;
3324
3536
  }
3325
3537
  const operationIds = operations.map((o) => o.id);
3326
3538
  const [, execErr] = await attempt(
3327
- () => this.#db.deleteFrom(NOORM_TABLES.executions).where("change_id", "in", operationIds).execute()
3539
+ () => this.#ndb.deleteFrom(this.#tables.executions).where("change_id", "in", operationIds).execute()
3328
3540
  );
3329
3541
  if (execErr) {
3330
3542
  observer.emit("error", {
@@ -3334,7 +3546,7 @@ var ChangeHistory = class {
3334
3546
  });
3335
3547
  }
3336
3548
  const [, changeErr] = await attempt(
3337
- () => this.#db.deleteFrom(NOORM_TABLES.change).where("id", "in", operationIds).execute()
3549
+ () => this.#ndb.deleteFrom(this.#tables.change).where("id", "in", operationIds).execute()
3338
3550
  );
3339
3551
  if (changeErr) {
3340
3552
  observer.emit("error", {
@@ -3354,7 +3566,7 @@ var ChangeHistory = class {
3354
3566
  * @param limit - Max records to return
3355
3567
  */
3356
3568
  async getHistory(name, limit) {
3357
- let query = this.#db.selectFrom(NOORM_TABLES.change).select([
3569
+ let query = this.#ndb.selectFrom(this.#tables.change).select([
3358
3570
  "id",
3359
3571
  "name",
3360
3572
  "direction",
@@ -3402,7 +3614,7 @@ var ChangeHistory = class {
3402
3614
  * @param limit - Max records to return
3403
3615
  */
3404
3616
  async getUnifiedHistory(changeTypes, limit) {
3405
- let query = this.#db.selectFrom(NOORM_TABLES.change).select([
3617
+ let query = this.#ndb.selectFrom(this.#tables.change).select([
3406
3618
  "id",
3407
3619
  "name",
3408
3620
  "change_type",
@@ -3458,7 +3670,7 @@ var ChangeHistory = class {
3458
3670
  */
3459
3671
  async getFileHistory(operationId) {
3460
3672
  const [records, err] = await attempt(
3461
- () => this.#db.selectFrom(NOORM_TABLES.executions).select([
3673
+ () => this.#ndb.selectFrom(this.#tables.executions).select([
3462
3674
  "id",
3463
3675
  "change_id",
3464
3676
  "filepath",
@@ -3508,9 +3720,13 @@ var ChangeHistory = class {
3508
3720
  };
3509
3721
  var Tracker = class {
3510
3722
  #db;
3723
+ #ndb;
3724
+ #tables;
3511
3725
  #configName;
3512
- constructor(db, configName) {
3726
+ constructor(db, configName, dialect = "sqlite") {
3513
3727
  this.#db = db;
3728
+ this.#ndb = noormDb(db, dialect);
3729
+ this.#tables = getNoormTables(dialect);
3514
3730
  this.#configName = configName;
3515
3731
  }
3516
3732
  /**
@@ -3533,15 +3749,16 @@ var Tracker = class {
3533
3749
  return { needsRun: true, reason: "force" };
3534
3750
  }
3535
3751
  const [record, err] = await attempt(
3536
- () => this.#db.selectFrom(NOORM_TABLES.executions).innerJoin(
3537
- NOORM_TABLES.change,
3538
- `${NOORM_TABLES.change}.id`,
3539
- `${NOORM_TABLES.executions}.change_id`
3752
+ () => this.#ndb.selectFrom(this.#tables.executions).innerJoin(
3753
+ this.#tables.change,
3754
+ `${this.#tables.change}.id`,
3755
+ `${this.#tables.executions}.change_id`
3756
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3540
3757
  ).select((eb) => [
3541
- eb.ref(`${NOORM_TABLES.executions}.checksum`).as("checksum"),
3542
- eb.ref(`${NOORM_TABLES.executions}.status`).as("exec_status"),
3543
- eb.ref(`${NOORM_TABLES.change}.status`).as("change_status")
3544
- ]).where(`${NOORM_TABLES.executions}.filepath`, "=", filepath).where(`${NOORM_TABLES.change}.config_name`, "=", this.#configName).orderBy(`${NOORM_TABLES.executions}.id`, "desc").limit(1).executeTakeFirst()
3758
+ eb.ref(`${this.#tables.executions}.checksum`).as("checksum"),
3759
+ eb.ref(`${this.#tables.executions}.status`).as("exec_status"),
3760
+ eb.ref(`${this.#tables.change}.status`).as("change_status")
3761
+ ]).where(`${this.#tables.executions}.filepath`, "=", filepath).where(`${this.#tables.change}.config_name`, "=", this.#configName).orderBy(`${this.#tables.executions}.id`, "desc").limit(1).executeTakeFirst()
3545
3762
  );
3546
3763
  if (err) {
3547
3764
  observer.emit("error", {
@@ -3597,7 +3814,7 @@ var Tracker = class {
3597
3814
  const direction = data2.direction ?? "commit";
3598
3815
  const dbDirection = direction === "commit" ? "change" : "revert";
3599
3816
  const [result, err] = await attempt(
3600
- () => this.#db.insertInto(NOORM_TABLES.change).values({
3817
+ () => this.#ndb.insertInto(this.#tables.change).values({
3601
3818
  name: data2.name,
3602
3819
  change_type: data2.changeType,
3603
3820
  direction: dbDirection,
@@ -3634,7 +3851,7 @@ var Tracker = class {
3634
3851
  */
3635
3852
  async recordExecution(data2) {
3636
3853
  const [, err] = await attempt(
3637
- () => this.#db.insertInto(NOORM_TABLES.executions).values({
3854
+ () => this.#ndb.insertInto(this.#tables.executions).values({
3638
3855
  change_id: data2.changeId,
3639
3856
  filepath: data2.filepath,
3640
3857
  file_type: "sql",
@@ -3668,7 +3885,7 @@ var Tracker = class {
3668
3885
  async finalizeOperation(operationId, status, durationMs, checksum, errorMessage) {
3669
3886
  const truncatedError = errorMessage ? errorMessage.slice(0, 2e3) : "";
3670
3887
  const [result, err] = await attempt(
3671
- () => this.#db.updateTable(NOORM_TABLES.change).set({
3888
+ () => this.#ndb.updateTable(this.#tables.change).set({
3672
3889
  status,
3673
3890
  duration_ms: Math.round(durationMs),
3674
3891
  checksum: checksum ?? "",
@@ -3719,7 +3936,7 @@ var Tracker = class {
3719
3936
  status: "pending"
3720
3937
  }));
3721
3938
  const [, err] = await attempt(
3722
- () => this.#db.insertInto(NOORM_TABLES.executions).values(values).execute()
3939
+ () => this.#ndb.insertInto(this.#tables.executions).values(values).execute()
3723
3940
  );
3724
3941
  if (err) {
3725
3942
  const errMsg = err instanceof Error ? err.message : String(err);
@@ -3747,7 +3964,7 @@ var Tracker = class {
3747
3964
  */
3748
3965
  async updateFileExecution(operationId, filepath, status, durationMs, errorMessage, skipReason) {
3749
3966
  const [result, err] = await attempt(
3750
- () => this.#db.updateTable(NOORM_TABLES.executions).set({
3967
+ () => this.#ndb.updateTable(this.#tables.executions).set({
3751
3968
  status,
3752
3969
  duration_ms: Math.round(durationMs),
3753
3970
  error_message: errorMessage ?? "",
@@ -3787,7 +4004,7 @@ var Tracker = class {
3787
4004
  */
3788
4005
  async skipRemainingFiles(operationId, reason) {
3789
4006
  const [, err] = await attempt(
3790
- () => this.#db.updateTable(NOORM_TABLES.executions).set({
4007
+ () => this.#ndb.updateTable(this.#tables.executions).set({
3791
4008
  status: "skipped",
3792
4009
  skip_reason: reason
3793
4010
  }).where("change_id", "=", operationId).where("status", "=", "pending").execute()
@@ -3818,7 +4035,7 @@ var Tracker = class {
3818
4035
  return { needsRun: true, reason: "force" };
3819
4036
  }
3820
4037
  const [record, err] = await attempt(
3821
- () => this.#db.selectFrom(NOORM_TABLES.change).select(["status", "checksum"]).where("name", "=", name).where("direction", "=", "change").where("config_name", "=", this.#configName).orderBy("id", "desc").limit(1).executeTakeFirst()
4038
+ () => this.#ndb.selectFrom(this.#tables.change).select(["status", "checksum"]).where("name", "=", name).where("direction", "=", "change").where("config_name", "=", this.#configName).orderBy("id", "desc").limit(1).executeTakeFirst()
3822
4039
  );
3823
4040
  if (err) {
3824
4041
  observer.emit("error", {
@@ -3872,11 +4089,13 @@ var Tracker = class {
3872
4089
  var ChangeTracker = class extends Tracker {
3873
4090
  // Store db and configName for change-specific queries
3874
4091
  // (Tracker uses private fields, so we need our own references)
3875
- #db;
4092
+ #ndb;
4093
+ #tables;
3876
4094
  #configName;
3877
- constructor(db, configName) {
3878
- super(db, configName);
3879
- this.#db = db;
4095
+ constructor(db, configName, dialect = "sqlite") {
4096
+ super(db, configName, dialect);
4097
+ this.#ndb = noormDb(db, dialect);
4098
+ this.#tables = getNoormTables(dialect);
3880
4099
  this.#configName = configName;
3881
4100
  }
3882
4101
  /**
@@ -3888,7 +4107,7 @@ var ChangeTracker = class extends Tracker {
3888
4107
  */
3889
4108
  async canRevert(name, force) {
3890
4109
  const [record, err] = await attempt(
3891
- () => this.#db.selectFrom(NOORM_TABLES.change).select(["status"]).where("name", "=", name).where("change_type", "=", "change").where("direction", "=", "change").where("config_name", "=", this.#configName).orderBy("id", "desc").limit(1).executeTakeFirst()
4110
+ () => this.#ndb.selectFrom(this.#tables.change).select(["status"]).where("name", "=", name).where("change_type", "=", "change").where("direction", "=", "change").where("config_name", "=", this.#configName).orderBy("id", "desc").limit(1).executeTakeFirst()
3892
4111
  );
3893
4112
  if (err) {
3894
4113
  observer.emit("error", {
@@ -3928,11 +4147,11 @@ var ChangeTracker = class extends Tracker {
3928
4147
  */
3929
4148
  async markAsReverted(name) {
3930
4149
  const [record] = await attempt(
3931
- () => this.#db.selectFrom(NOORM_TABLES.change).select(["id"]).where("name", "=", name).where("change_type", "=", "change").where("direction", "=", "change").where("config_name", "=", this.#configName).orderBy("id", "desc").limit(1).executeTakeFirst()
4150
+ () => this.#ndb.selectFrom(this.#tables.change).select(["id"]).where("name", "=", name).where("change_type", "=", "change").where("direction", "=", "change").where("config_name", "=", this.#configName).orderBy("id", "desc").limit(1).executeTakeFirst()
3932
4151
  );
3933
4152
  if (record) {
3934
4153
  await attempt(
3935
- () => this.#db.updateTable(NOORM_TABLES.change).set({ status: "reverted" }).where("id", "=", record.id).execute()
4154
+ () => this.#ndb.updateTable(this.#tables.change).set({ status: "reverted" }).where("id", "=", record.id).execute()
3936
4155
  );
3937
4156
  }
3938
4157
  }
@@ -3948,7 +4167,7 @@ var ChangeTracker = class extends Tracker {
3948
4167
  */
3949
4168
  async markAllAsStale() {
3950
4169
  const [result, err] = await attempt(
3951
- () => this.#db.updateTable(NOORM_TABLES.change).set({ status: "stale" }).where("direction", "=", "change").where("status", "in", ["success", "failed", "pending"]).where("config_name", "=", this.#configName).execute()
4170
+ () => this.#ndb.updateTable(this.#tables.change).set({ status: "stale" }).where("direction", "=", "change").where("status", "in", ["success", "failed", "pending"]).where("config_name", "=", this.#configName).execute()
3952
4171
  );
3953
4172
  if (err) {
3954
4173
  observer.emit("error", {
@@ -4060,7 +4279,7 @@ var LockManager = class {
4060
4279
  observer.emit("lock:acquiring", { configName, identity });
4061
4280
  while (true) {
4062
4281
  await this.cleanupExpired(db, configName, opts.dialect);
4063
- const existing = await this.getLock(db, configName);
4282
+ const existing = await this.getLock(db, configName, opts.dialect);
4064
4283
  if (!existing) {
4065
4284
  const lock = await this.createLock(db, configName, identity, opts);
4066
4285
  observer.emit("lock:acquired", {
@@ -4112,18 +4331,21 @@ var LockManager = class {
4112
4331
  * @param db - Kysely database instance
4113
4332
  * @param configName - Config/database scope
4114
4333
  * @param identity - Identity of the lock holder
4334
+ * @param dialect - Database dialect for schema-aware table resolution
4115
4335
  * @throws LockNotFoundError if no lock exists
4116
4336
  * @throws LockOwnershipError if lock is held by someone else
4117
4337
  */
4118
- async release(db, configName, identity) {
4119
- const existing = await this.getLock(db, configName);
4338
+ async release(db, configName, identity, dialect) {
4339
+ const ndb = noormDb(db, dialect);
4340
+ const tables = getNoormTables(dialect);
4341
+ const existing = await this.getLock(db, configName, dialect);
4120
4342
  if (!existing) {
4121
4343
  throw new LockNotFoundError(configName, identity);
4122
4344
  }
4123
4345
  if (existing.lockedBy !== identity) {
4124
4346
  throw new LockOwnershipError(configName, identity, existing.lockedBy);
4125
4347
  }
4126
- await db.deleteFrom(NOORM_TABLES.lock).where("config_name", "=", configName).where("locked_by", "=", identity).execute();
4348
+ await ndb.deleteFrom(tables.lock).where("config_name", "=", configName).where("locked_by", "=", identity).execute();
4127
4349
  observer.emit("lock:released", { configName, identity });
4128
4350
  }
4129
4351
  /**
@@ -4134,14 +4356,17 @@ var LockManager = class {
4134
4356
  *
4135
4357
  * @param db - Kysely database instance
4136
4358
  * @param configName - Config/database scope
4359
+ * @param dialect - Database dialect for schema-aware table resolution
4137
4360
  * @returns true if a lock was released, false if none existed
4138
4361
  */
4139
- async forceRelease(db, configName) {
4140
- const existing = await this.getLock(db, configName);
4362
+ async forceRelease(db, configName, dialect) {
4363
+ const ndb = noormDb(db, dialect);
4364
+ const tables = getNoormTables(dialect);
4365
+ const existing = await this.getLock(db, configName, dialect);
4141
4366
  if (!existing) {
4142
4367
  return false;
4143
4368
  }
4144
- await db.deleteFrom(NOORM_TABLES.lock).where("config_name", "=", configName).execute();
4369
+ await ndb.deleteFrom(tables.lock).where("config_name", "=", configName).execute();
4145
4370
  observer.emit("lock:released", {
4146
4371
  configName,
4147
4372
  identity: existing.lockedBy
@@ -4162,11 +4387,12 @@ var LockManager = class {
4162
4387
  * @returns Result of the operation
4163
4388
  */
4164
4389
  async withLock(db, configName, identity, operation, options = {}) {
4390
+ const opts = { ...DEFAULT_LOCK_OPTIONS, ...options };
4165
4391
  await this.acquire(db, configName, identity, options);
4166
4392
  try {
4167
4393
  return await operation();
4168
4394
  } finally {
4169
- const [, err] = await attempt(() => this.release(db, configName, identity));
4395
+ const [, err] = await attempt(() => this.release(db, configName, identity, opts.dialect));
4170
4396
  if (err) {
4171
4397
  observer.emit("error", {
4172
4398
  source: "lock",
@@ -4184,12 +4410,13 @@ var LockManager = class {
4184
4410
  * @param db - Kysely database instance
4185
4411
  * @param configName - Config/database scope
4186
4412
  * @param identity - Expected lock holder
4413
+ * @param dialect - Database dialect for schema-aware table resolution
4187
4414
  * @throws LockExpiredError if lock has expired
4188
4415
  * @throws LockOwnershipError if lock is held by someone else
4189
4416
  * @throws LockNotFoundError if no lock exists
4190
4417
  */
4191
4418
  async validate(db, configName, identity, dialect = "postgres") {
4192
- const existing = await this.getLock(db, configName);
4419
+ const existing = await this.getLock(db, configName, dialect);
4193
4420
  if (!existing) {
4194
4421
  throw new LockNotFoundError(configName, identity);
4195
4422
  }
@@ -4211,7 +4438,8 @@ var LockManager = class {
4211
4438
  * @returns Updated lock state
4212
4439
  */
4213
4440
  async extend(db, configName, identity, options = {}) {
4214
- await this.validate(db, configName, identity);
4441
+ const opts = { ...DEFAULT_LOCK_OPTIONS, ...options };
4442
+ await this.validate(db, configName, identity, opts.dialect);
4215
4443
  return this.extendLock(db, configName, identity, options);
4216
4444
  }
4217
4445
  /**
@@ -4224,7 +4452,7 @@ var LockManager = class {
4224
4452
  */
4225
4453
  async status(db, configName, dialect = "postgres") {
4226
4454
  await this.cleanupExpired(db, configName, dialect);
4227
- const lock = await this.getLock(db, configName);
4455
+ const lock = await this.getLock(db, configName, dialect);
4228
4456
  return {
4229
4457
  isLocked: lock !== null,
4230
4458
  lock
@@ -4236,8 +4464,10 @@ var LockManager = class {
4236
4464
  /**
4237
4465
  * Get lock from database, or null if none exists.
4238
4466
  */
4239
- async getLock(db, configName) {
4240
- const row = await db.selectFrom(NOORM_TABLES.lock).selectAll().where("config_name", "=", configName).executeTakeFirst();
4467
+ async getLock(db, configName, dialect) {
4468
+ const ndb = noormDb(db, dialect);
4469
+ const tables = getNoormTables(dialect);
4470
+ const row = await ndb.selectFrom(tables.lock).selectAll().where("config_name", "=", configName).executeTakeFirst();
4241
4471
  if (!row) {
4242
4472
  return null;
4243
4473
  }
@@ -4252,9 +4482,11 @@ var LockManager = class {
4252
4482
  * Create a new lock in the database.
4253
4483
  */
4254
4484
  async createLock(db, configName, identity, opts) {
4485
+ const ndb = noormDb(db, opts.dialect);
4486
+ const tables = getNoormTables(opts.dialect);
4255
4487
  const now = /* @__PURE__ */ new Date();
4256
4488
  const expiresAt = new Date(now.getTime() + opts.timeout);
4257
- await db.insertInto(NOORM_TABLES.lock).values({
4489
+ await ndb.insertInto(tables.lock).values({
4258
4490
  config_name: configName,
4259
4491
  locked_by: identity,
4260
4492
  locked_at: formatDateForDialect(now, opts.dialect),
@@ -4274,6 +4506,8 @@ var LockManager = class {
4274
4506
  async extendLock(db, configName, identity, opts) {
4275
4507
  const dialect = opts.dialect ?? DEFAULT_LOCK_OPTIONS.dialect;
4276
4508
  const timeout = opts.timeout ?? DEFAULT_LOCK_OPTIONS.timeout;
4509
+ const ndb = noormDb(db, dialect);
4510
+ const tables = getNoormTables(dialect);
4277
4511
  const now = /* @__PURE__ */ new Date();
4278
4512
  const expiresAt = new Date(now.getTime() + timeout);
4279
4513
  const updateValues = {
@@ -4282,19 +4516,21 @@ var LockManager = class {
4282
4516
  if (opts.reason !== void 0) {
4283
4517
  updateValues["reason"] = opts.reason;
4284
4518
  }
4285
- await db.updateTable(NOORM_TABLES.lock).set(updateValues).where("config_name", "=", configName).where("locked_by", "=", identity).execute();
4286
- const lock = await this.getLock(db, configName);
4519
+ await ndb.updateTable(tables.lock).set(updateValues).where("config_name", "=", configName).where("locked_by", "=", identity).execute();
4520
+ const lock = await this.getLock(db, configName, dialect);
4287
4521
  return lock;
4288
4522
  }
4289
4523
  /**
4290
4524
  * Clean up expired locks.
4291
4525
  */
4292
4526
  async cleanupExpired(db, configName, dialect = "postgres") {
4527
+ const ndb = noormDb(db, dialect);
4528
+ const tables = getNoormTables(dialect);
4293
4529
  const now = /* @__PURE__ */ new Date();
4294
4530
  const nowForDb = formatDateForDialect(now, dialect);
4295
- const expired = await db.selectFrom(NOORM_TABLES.lock).select(["locked_by"]).where("config_name", "=", configName).where("expires_at", "<", nowForDb).executeTakeFirst();
4531
+ const expired = await ndb.selectFrom(tables.lock).select(["locked_by"]).where("config_name", "=", configName).where("expires_at", "<", nowForDb).executeTakeFirst();
4296
4532
  if (expired) {
4297
- await db.deleteFrom(NOORM_TABLES.lock).where("config_name", "=", configName).where("expires_at", "<", nowForDb).execute();
4533
+ await ndb.deleteFrom(tables.lock).where("config_name", "=", configName).where("expires_at", "<", nowForDb).execute();
4298
4534
  observer.emit("lock:expired", {
4299
4535
  configName,
4300
4536
  previousHolder: expired.locked_by
@@ -4353,7 +4589,7 @@ async function executeChange(context, change, options = {}) {
4353
4589
  return createFailedResult(change.name, "change", checksumErr.message, start);
4354
4590
  }
4355
4591
  const changeChecksum = computeCombinedChecksum(checksums);
4356
- const history = new ChangeHistory(context.db, context.configName);
4592
+ const history = new ChangeHistory(context.db, context.configName, context.dialect ?? "postgres");
4357
4593
  if (!opts.dryRun && !opts.preview) {
4358
4594
  const needsRunResult = await history.needsRun(
4359
4595
  change.name,
@@ -4402,7 +4638,7 @@ async function executeChange(context, change, options = {}) {
4402
4638
  start
4403
4639
  )
4404
4640
  );
4405
- await attempt(() => lockManager.release(context.db, context.configName, identity));
4641
+ await attempt(() => lockManager.release(context.db, context.configName, identity, context.dialect ?? "postgres"));
4406
4642
  if (execErr) {
4407
4643
  throw execErr;
4408
4644
  }
@@ -4425,8 +4661,8 @@ async function revertChange(context, change, options = {}) {
4425
4661
  return createFailedResult(change.name, "revert", checksumErr.message, start);
4426
4662
  }
4427
4663
  const revertChecksum = computeCombinedChecksum(checksums);
4428
- const history = new ChangeHistory(context.db, context.configName);
4429
- const tracker = new ChangeTracker(context.db, context.configName);
4664
+ const history = new ChangeHistory(context.db, context.configName, context.dialect ?? "postgres");
4665
+ const tracker = new ChangeTracker(context.db, context.configName, context.dialect ?? "postgres");
4430
4666
  if (!opts.dryRun && !opts.preview) {
4431
4667
  const canRevertResult = await tracker.canRevert(change.name, opts.force);
4432
4668
  if (!canRevertResult.canRevert) {
@@ -4474,7 +4710,7 @@ async function revertChange(context, change, options = {}) {
4474
4710
  start
4475
4711
  )
4476
4712
  );
4477
- await attempt(() => lockManager.release(context.db, context.configName, identity));
4713
+ await attempt(() => lockManager.release(context.db, context.configName, identity, context.dialect ?? "postgres"));
4478
4714
  if (execErr) {
4479
4715
  throw execErr;
4480
4716
  }
@@ -4888,7 +5124,7 @@ var ChangeManager = class {
4888
5124
  #history;
4889
5125
  constructor(context) {
4890
5126
  this.#context = context;
4891
- this.#history = new ChangeHistory(context.db, context.configName);
5127
+ this.#history = new ChangeHistory(context.db, context.configName, context.dialect ?? "postgres");
4892
5128
  }
4893
5129
  // ─────────────────────────────────────────────────────────
4894
5130
  // List
@@ -5508,7 +5744,7 @@ async function runFile(context, filepath, options = {}) {
5508
5744
  filepath,
5509
5745
  configName: context.configName
5510
5746
  });
5511
- const tracker = new Tracker(context.db, context.configName);
5747
+ const tracker = new Tracker(context.db, context.configName, context.dialect ?? "postgres");
5512
5748
  const operationName = `run:${(/* @__PURE__ */ new Date()).toISOString()}`;
5513
5749
  const [operationId, createErr] = await attempt(
5514
5750
  () => tracker.createOperation({
@@ -5640,7 +5876,7 @@ async function executeFiles2(context, files, runOptions, execOptions) {
5640
5876
  durationMs: durationMs2
5641
5877
  };
5642
5878
  }
5643
- const tracker = execOptions.tracker ?? new Tracker(context.db, context.configName);
5879
+ const tracker = execOptions.tracker ?? new Tracker(context.db, context.configName, context.dialect ?? "postgres");
5644
5880
  const [operationId, createErr] = await attempt(
5645
5881
  () => tracker.createOperation({
5646
5882
  name: execOptions.operationName,
@@ -6226,13 +6462,14 @@ var RunNamespace = class {
6226
6462
  configName: this.#state.config.name,
6227
6463
  identity: this.#state.identity,
6228
6464
  projectRoot: this.#state.projectRoot,
6465
+ dialect: this.#state.config.connection.dialect,
6229
6466
  config: this.#state.config,
6230
6467
  secrets: state.getAllSecrets(this.#state.config.name),
6231
6468
  globalSecrets: state.getAllGlobalSecrets()
6232
6469
  };
6233
6470
  }
6234
6471
  };
6235
- var EXCLUDED_SCHEMAS = ["pg_catalog", "information_schema", "pg_toast"];
6472
+ var EXCLUDED_SCHEMAS = ["pg_catalog", "information_schema", "pg_toast", "noorm"];
6236
6473
  var postgresExploreOperations = {
6237
6474
  async getOverview(db) {
6238
6475
  const [tables, views, procedures, functions, types, indexes, foreignKeys] = await Promise.all([
@@ -7430,7 +7667,7 @@ var mysqlExploreOperations = {
7430
7667
  };
7431
7668
  }
7432
7669
  };
7433
- var EXCLUDED_SCHEMAS2 = ["sys", "INFORMATION_SCHEMA", "guest"];
7670
+ var EXCLUDED_SCHEMAS2 = ["sys", "INFORMATION_SCHEMA", "guest", "noorm"];
7434
7671
  var mssqlExploreOperations = {
7435
7672
  async getOverview(db) {
7436
7673
  const [tables, views, procedures, functions, types, indexes, foreignKeys] = await Promise.all([
@@ -8644,10 +8881,10 @@ function getTeardownOperations(dialect) {
8644
8881
  }
8645
8882
 
8646
8883
  // src/core/teardown/operations.ts
8647
- var NOORM_TABLE_NAMES = new Set(Object.values(NOORM_TABLES));
8648
8884
  function isNoormTable2(name) {
8649
8885
  if (!name) return false;
8650
- return name.startsWith("__noorm_") || NOORM_TABLE_NAMES.has(name);
8886
+ if (name.startsWith("__noorm_")) return true;
8887
+ return false;
8651
8888
  }
8652
8889
  async function truncateData(db, dialect, options = {}) {
8653
8890
  const startTime = performance.now();
@@ -8820,11 +9057,13 @@ async function teardownSchema(db, dialect, options = {}) {
8820
9057
  if (options.configName && options.executedBy && !options.dryRun) {
8821
9058
  const tracker = new ChangeTracker(
8822
9059
  db,
8823
- options.configName
9060
+ options.configName,
9061
+ dialect
8824
9062
  );
8825
9063
  const history = new ChangeHistory(
8826
9064
  db,
8827
- options.configName
9065
+ options.configName,
9066
+ dialect
8828
9067
  );
8829
9068
  result.staleCount = await tracker.markAllAsStale();
8830
9069
  const parts = [
@@ -9053,7 +9292,8 @@ var LockNamespace = class {
9053
9292
  await lockManager.release(
9054
9293
  this.#kysely,
9055
9294
  this.#state.config.name,
9056
- identityStr
9295
+ identityStr,
9296
+ this.#state.config.connection.dialect
9057
9297
  );
9058
9298
  }
9059
9299
  /**
@@ -9105,7 +9345,8 @@ var LockNamespace = class {
9105
9345
  const lockManager = getLockManager();
9106
9346
  return lockManager.forceRelease(
9107
9347
  this.#kysely,
9108
- this.#state.config.name
9348
+ this.#state.config.name,
9349
+ this.#state.config.connection.dialect
9109
9350
  );
9110
9351
  }
9111
9352
  // ─────────────────────────────────────────────────────
@@ -9118,9 +9359,11 @@ var LockNamespace = class {
9118
9359
  return this.#state.connection.db;
9119
9360
  }
9120
9361
  };
9121
- async function getUsersWithoutVaultAccess(db) {
9362
+ async function getUsersWithoutVaultAccess(db, dialect) {
9363
+ const ndb = noormDb(db, dialect);
9364
+ const tables = getNoormTables(dialect);
9122
9365
  const [rows, err] = await attempt(async () => {
9123
- return db.selectFrom(NOORM_TABLES.identities).select([
9366
+ return ndb.selectFrom(tables.identities).select([
9124
9367
  "identity_hash",
9125
9368
  "public_key",
9126
9369
  "name",
@@ -9135,11 +9378,13 @@ async function getUsersWithoutVaultAccess(db) {
9135
9378
  email: r.email
9136
9379
  }));
9137
9380
  }
9138
- async function propagateVaultKey(db, vaultKey) {
9139
- const users = await getUsersWithoutVaultAccess(db);
9381
+ async function propagateVaultKey(db, vaultKey, dialect) {
9382
+ const ndb = noormDb(db, dialect);
9383
+ const tables = getNoormTables(dialect);
9384
+ const users = await getUsersWithoutVaultAccess(db, dialect);
9140
9385
  if (users.length === 0) {
9141
9386
  const [countResult2] = await attempt(async () => {
9142
- return db.selectFrom(NOORM_TABLES.identities).select(db.fn.count("id").as("count")).where("encrypted_vault_key", "is not", null).executeTakeFirst();
9387
+ return ndb.selectFrom(tables.identities).select(ndb.fn.count("id").as("count")).where("encrypted_vault_key", "is not", null).executeTakeFirst();
9143
9388
  });
9144
9389
  return {
9145
9390
  propagatedTo: [],
@@ -9151,7 +9396,7 @@ async function propagateVaultKey(db, vaultKey) {
9151
9396
  const encrypted = encryptVaultKey(vaultKey, user.publicKey);
9152
9397
  const encryptedJson = JSON.stringify(encrypted);
9153
9398
  const [, err] = await attempt(async () => {
9154
- return db.updateTable(NOORM_TABLES.identities).set({ encrypted_vault_key: encryptedJson }).where("identity_hash", "=", user.identityHash).execute();
9399
+ return ndb.updateTable(tables.identities).set({ encrypted_vault_key: encryptedJson }).where("identity_hash", "=", user.identityHash).execute();
9155
9400
  });
9156
9401
  if (!err) {
9157
9402
  propagatedTo.push(user.identityHash);
@@ -9162,7 +9407,7 @@ async function propagateVaultKey(db, vaultKey) {
9162
9407
  }
9163
9408
  }
9164
9409
  const [countResult] = await attempt(async () => {
9165
- return db.selectFrom(NOORM_TABLES.identities).select(db.fn.count("id").as("count")).where("encrypted_vault_key", "is not", null).executeTakeFirst();
9410
+ return ndb.selectFrom(tables.identities).select(ndb.fn.count("id").as("count")).where("encrypted_vault_key", "is not", null).executeTakeFirst();
9166
9411
  });
9167
9412
  const totalWithAccess = countResult ? Number(countResult.count) : 0;
9168
9413
  const alreadyHadAccess = totalWithAccess - propagatedTo.length;
@@ -9242,18 +9487,20 @@ async function copyVaultSecrets(sourceConfig, destConfig, keys, identityHash, pr
9242
9487
  const sourceVaultKey = await getVaultKey(
9243
9488
  ctx.source.db,
9244
9489
  identityHash,
9245
- privateKey
9490
+ privateKey,
9491
+ ctx.source.dialect
9246
9492
  );
9247
9493
  if (!sourceVaultKey) {
9248
9494
  throw new Error(`No vault access on source config "${sourceConfig.name}"`);
9249
9495
  }
9250
- const destStatus = await getVaultStatus(ctx.destination.db, identityHash);
9496
+ const destStatus = await getVaultStatus(ctx.destination.db, identityHash, ctx.destination.dialect);
9251
9497
  let destVaultKey = null;
9252
9498
  if (!destStatus.isInitialized) {
9253
9499
  const [newKey, initErr] = await initializeVault(
9254
9500
  ctx.destination.db,
9255
9501
  identityHash,
9256
- publicKey
9502
+ publicKey,
9503
+ ctx.destination.dialect
9257
9504
  );
9258
9505
  if (initErr) {
9259
9506
  throw new Error(`Failed to initialize vault on destination: ${initErr.message}`);
@@ -9265,13 +9512,14 @@ async function copyVaultSecrets(sourceConfig, destConfig, keys, identityHash, pr
9265
9512
  destVaultKey = await getVaultKey(
9266
9513
  ctx.destination.db,
9267
9514
  identityHash,
9268
- privateKey
9515
+ privateKey,
9516
+ ctx.destination.dialect
9269
9517
  );
9270
9518
  }
9271
9519
  if (!destVaultKey) {
9272
9520
  throw new Error("Failed to get vault key for destination");
9273
9521
  }
9274
- const allSourceSecrets = await getAllVaultSecrets(ctx.source.db, sourceVaultKey);
9522
+ const allSourceSecrets = await getAllVaultSecrets(ctx.source.db, sourceVaultKey, ctx.source.dialect);
9275
9523
  const secretsToCopy = keys === "all" ? Object.entries(allSourceSecrets) : Object.entries(allSourceSecrets).filter(([key]) => keys.includes(key));
9276
9524
  const result = {
9277
9525
  copied: [],
@@ -9289,7 +9537,7 @@ async function copyVaultSecrets(sourceConfig, destConfig, keys, identityHash, pr
9289
9537
  }
9290
9538
  }
9291
9539
  for (const [key, secret] of secretsToCopy) {
9292
- const exists = await vaultSecretExists(ctx.destination.db, key);
9540
+ const exists = await vaultSecretExists(ctx.destination.db, key, ctx.destination.dialect);
9293
9541
  if (exists && !force) {
9294
9542
  result.skipped.push(key);
9295
9543
  continue;
@@ -9300,7 +9548,8 @@ async function copyVaultSecrets(sourceConfig, destConfig, keys, identityHash, pr
9300
9548
  destVaultKey,
9301
9549
  key,
9302
9550
  secret.value,
9303
- setBy
9551
+ setBy,
9552
+ ctx.destination.dialect
9304
9553
  );
9305
9554
  if (setErr) {
9306
9555
  result.errors.push({ key, error: setErr.message });
@@ -9341,7 +9590,8 @@ var VaultNamespace = class {
9341
9590
  return initializeVault(
9342
9591
  this.#kysely,
9343
9592
  this.#identityHash,
9344
- this.#publicKey
9593
+ this.#publicKey,
9594
+ this.#dialect
9345
9595
  );
9346
9596
  }
9347
9597
  /**
@@ -9355,7 +9605,8 @@ var VaultNamespace = class {
9355
9605
  async status() {
9356
9606
  return getVaultStatus(
9357
9607
  this.#kysely,
9358
- this.#identityHash
9608
+ this.#identityHash,
9609
+ this.#dialect
9359
9610
  );
9360
9611
  }
9361
9612
  // ─────────────────────────────────────────────────────
@@ -9377,7 +9628,8 @@ var VaultNamespace = class {
9377
9628
  vaultKey,
9378
9629
  key,
9379
9630
  value,
9380
- formatIdentity(this.#state.identity)
9631
+ formatIdentity(this.#state.identity),
9632
+ this.#dialect
9381
9633
  );
9382
9634
  }
9383
9635
  /**
@@ -9394,7 +9646,8 @@ var VaultNamespace = class {
9394
9646
  return getVaultSecret(
9395
9647
  this.#kysely,
9396
9648
  vaultKey,
9397
- key
9649
+ key,
9650
+ this.#dialect
9398
9651
  );
9399
9652
  }
9400
9653
  /**
@@ -9410,7 +9663,8 @@ var VaultNamespace = class {
9410
9663
  if (!vaultKey) return {};
9411
9664
  return getAllVaultSecrets(
9412
9665
  this.#kysely,
9413
- vaultKey
9666
+ vaultKey,
9667
+ this.#dialect
9414
9668
  );
9415
9669
  }
9416
9670
  /**
@@ -9423,7 +9677,8 @@ var VaultNamespace = class {
9423
9677
  */
9424
9678
  async list() {
9425
9679
  return listVaultSecretKeys(
9426
- this.#kysely
9680
+ this.#kysely,
9681
+ this.#dialect
9427
9682
  );
9428
9683
  }
9429
9684
  /**
@@ -9437,7 +9692,8 @@ var VaultNamespace = class {
9437
9692
  async delete(key) {
9438
9693
  return deleteVaultSecret(
9439
9694
  this.#kysely,
9440
- key
9695
+ key,
9696
+ this.#dialect
9441
9697
  );
9442
9698
  }
9443
9699
  /**
@@ -9451,7 +9707,8 @@ var VaultNamespace = class {
9451
9707
  async exists(key) {
9452
9708
  return vaultSecretExists(
9453
9709
  this.#kysely,
9454
- key
9710
+ key,
9711
+ this.#dialect
9455
9712
  );
9456
9713
  }
9457
9714
  // ─────────────────────────────────────────────────────
@@ -9472,7 +9729,8 @@ var VaultNamespace = class {
9472
9729
  }
9473
9730
  return propagateVaultKey(
9474
9731
  this.#kysely,
9475
- vaultKey
9732
+ vaultKey,
9733
+ this.#dialect
9476
9734
  );
9477
9735
  }
9478
9736
  /**
@@ -9511,11 +9769,15 @@ var VaultNamespace = class {
9511
9769
  const identity = this.#state.identity;
9512
9770
  return identity["publicKey"] ?? "";
9513
9771
  }
9772
+ get #dialect() {
9773
+ return this.#state.config.connection.dialect;
9774
+ }
9514
9775
  async #getVaultKey(privateKey) {
9515
9776
  return getVaultKey(
9516
9777
  this.#kysely,
9517
9778
  this.#identityHash,
9518
- privateKey
9779
+ privateKey,
9780
+ this.#dialect
9519
9781
  );
9520
9782
  }
9521
9783
  };