@absolutejs/auth 0.57.6 → 0.57.7

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.
@@ -3100,30 +3100,40 @@ var JOURNAL_DDL = `CREATE TABLE IF NOT EXISTS "auth_migrations" (
3100
3100
  var isJournalRow = (value) => typeof value === "object" && value !== null && typeof Reflect.get(value, "id") === "string";
3101
3101
  var isBlockName = (value) => Object.hasOwn(blockMigrations, value);
3102
3102
  var allBlockNames = () => Object.keys(blockMigrations).filter(isBlockName);
3103
- var applyOne = async (pool, id, sql, log) => {
3104
- await pool.query(sql);
3105
- await pool.query(`INSERT INTO "auth_migrations" ("id", "applied_at_ms") VALUES ($1, $2)`, [id, Date.now()]);
3103
+ var applyOne = async (client, id, sql, log) => {
3104
+ await client.query(sql);
3105
+ await client.query(`INSERT INTO "auth_migrations" ("id", "applied_at_ms") VALUES ($1, $2)`, [id, Date.now()]);
3106
3106
  log(`apply ${id}`);
3107
3107
  };
3108
- var runOne = async (pool, id, sql, applied, result, log) => {
3108
+ var runOne = async (client, id, sql, applied, result, log) => {
3109
3109
  if (applied.has(id)) {
3110
3110
  result.skipped.push(id);
3111
3111
  log(`skip ${id}`);
3112
3112
  return;
3113
3113
  }
3114
- await applyOne(pool, id, sql, log);
3114
+ await applyOne(client, id, sql, log);
3115
3115
  result.applied.push(id);
3116
3116
  };
3117
3117
  var runMigrations = async ({
3118
3118
  blocks,
3119
+ client,
3119
3120
  databaseUrl,
3120
3121
  log = console.log
3121
3122
  }) => {
3122
- const pool = new Pool({ connectionString: databaseUrl });
3123
+ let ownedPool;
3124
+ let migrationClient;
3125
+ if (client !== undefined) {
3126
+ migrationClient = client;
3127
+ } else {
3128
+ if (databaseUrl === undefined)
3129
+ throw new Error("runMigrations requires databaseUrl or client");
3130
+ ownedPool = new Pool({ connectionString: databaseUrl });
3131
+ migrationClient = ownedPool;
3132
+ }
3123
3133
  const result = { applied: [], skipped: [] };
3124
3134
  try {
3125
- await pool.query(JOURNAL_DDL);
3126
- const journal = await pool.query(`SELECT "id" FROM "auth_migrations"`);
3135
+ await migrationClient.query(JOURNAL_DDL);
3136
+ const journal = await migrationClient.query(`SELECT "id" FROM "auth_migrations"`);
3127
3137
  const applied = new Set(journal.rows.filter(isJournalRow).map((row) => row.id));
3128
3138
  const selected = blocks ?? allBlockNames();
3129
3139
  const flat = selected.flatMap((block) => blockMigrations[block].migrations.map((migration) => ({
@@ -3132,10 +3142,10 @@ var runMigrations = async ({
3132
3142
  })));
3133
3143
  await flat.reduce(async (prior, item) => {
3134
3144
  await prior;
3135
- return runOne(pool, item.id, item.sql, applied, result, log);
3145
+ return runOne(migrationClient, item.id, item.sql, applied, result, log);
3136
3146
  }, Promise.resolve());
3137
3147
  } finally {
3138
- await pool.end();
3148
+ await ownedPool?.end();
3139
3149
  }
3140
3150
  return result;
3141
3151
  };
@@ -3437,5 +3447,5 @@ var main = async () => {
3437
3447
  };
3438
3448
  await main();
3439
3449
 
3440
- //# debugId=F5FC77C8DEF0189164756E2164756E21
3450
+ //# debugId=C8D20760311031E264756E2164756E21
3441
3451
  //# sourceMappingURL=migrate.js.map