@tinycloud/cli 1.2.4-beta.3 → 1.2.5-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10965,17 +10965,31 @@ var init_dist2 = __esm({
10965
10965
  }
10966
10966
  async applyMigrationsOnDbUnlocked(dbName, options) {
10967
10967
  return this.withTelemetry("migrations.apply", dbName, async () => {
10968
- const listed = await this.queryOnDb(
10968
+ const probe = await this.queryOnDb(
10969
10969
  dbName,
10970
- `SELECT id FROM ${MIGRATIONS_TABLE} WHERE namespace = ? ORDER BY applied_at, id`,
10971
- [options.namespace],
10970
+ `SELECT name FROM sqlite_master WHERE type='table' AND name='${MIGRATIONS_TABLE}'`,
10971
+ [],
10972
10972
  { signal: options.signal }
10973
10973
  );
10974
- const tableMissing = !listed.ok && (listed.error.code === ErrorCodes.SQL_DATABASE_NOT_FOUND || isMissingTableError(listed.error.message));
10975
- if (!listed.ok && !tableMissing) return listed;
10976
- const appliedIds = new Set(
10977
- (listed.ok ? listed.data.rows : []).map((row) => rowValue(row, 0)).filter((id) => typeof id === "string")
10978
- );
10974
+ let tableMissing = probe.ok ? probe.data.rows.length === 0 : probe.error.code === ErrorCodes.SQL_DATABASE_NOT_FOUND || isMissingTableError(probe.error.message);
10975
+ if (!probe.ok && !tableMissing) return probe;
10976
+ const appliedIds = /* @__PURE__ */ new Set();
10977
+ if (!tableMissing) {
10978
+ const listed = await this.queryOnDb(
10979
+ dbName,
10980
+ `SELECT id FROM ${MIGRATIONS_TABLE} WHERE namespace = ? ORDER BY applied_at, id`,
10981
+ [options.namespace],
10982
+ { signal: options.signal }
10983
+ );
10984
+ tableMissing = !listed.ok && (listed.error.code === ErrorCodes.SQL_DATABASE_NOT_FOUND || isMissingTableError(listed.error.message));
10985
+ if (!listed.ok && !tableMissing) return listed;
10986
+ if (listed.ok) {
10987
+ for (const row of listed.data.rows) {
10988
+ const id = rowValue(row, 0);
10989
+ if (typeof id === "string") appliedIds.add(id);
10990
+ }
10991
+ }
10992
+ }
10979
10993
  const skipped = options.migrations.filter((migration) => appliedIds.has(migration.id)).map((migration) => migration.id);
10980
10994
  const pending = options.migrations.filter((migration) => !appliedIds.has(migration.id));
10981
10995
  const applied = [];