@tinycloud/sdk-services 3.2.4 → 3.2.5

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.cjs CHANGED
@@ -3817,17 +3817,31 @@ var SQLService = class extends BaseService {
3817
3817
  }
3818
3818
  async applyMigrationsOnDbUnlocked(dbName, options) {
3819
3819
  return this.withTelemetry("migrations.apply", dbName, async () => {
3820
- const listed = await this.queryOnDb(
3820
+ const probe = await this.queryOnDb(
3821
3821
  dbName,
3822
- `SELECT id FROM ${MIGRATIONS_TABLE} WHERE namespace = ? ORDER BY applied_at, id`,
3823
- [options.namespace],
3822
+ `SELECT name FROM sqlite_master WHERE type='table' AND name='${MIGRATIONS_TABLE}'`,
3823
+ [],
3824
3824
  { signal: options.signal }
3825
3825
  );
3826
- const tableMissing = !listed.ok && (listed.error.code === ErrorCodes.SQL_DATABASE_NOT_FOUND || isMissingTableError(listed.error.message));
3827
- if (!listed.ok && !tableMissing) return listed;
3828
- const appliedIds = new Set(
3829
- (listed.ok ? listed.data.rows : []).map((row) => rowValue(row, 0)).filter((id) => typeof id === "string")
3830
- );
3826
+ let tableMissing = probe.ok ? probe.data.rows.length === 0 : probe.error.code === ErrorCodes.SQL_DATABASE_NOT_FOUND || isMissingTableError(probe.error.message);
3827
+ if (!probe.ok && !tableMissing) return probe;
3828
+ const appliedIds = /* @__PURE__ */ new Set();
3829
+ if (!tableMissing) {
3830
+ const listed = await this.queryOnDb(
3831
+ dbName,
3832
+ `SELECT id FROM ${MIGRATIONS_TABLE} WHERE namespace = ? ORDER BY applied_at, id`,
3833
+ [options.namespace],
3834
+ { signal: options.signal }
3835
+ );
3836
+ tableMissing = !listed.ok && (listed.error.code === ErrorCodes.SQL_DATABASE_NOT_FOUND || isMissingTableError(listed.error.message));
3837
+ if (!listed.ok && !tableMissing) return listed;
3838
+ if (listed.ok) {
3839
+ for (const row of listed.data.rows) {
3840
+ const id = rowValue(row, 0);
3841
+ if (typeof id === "string") appliedIds.add(id);
3842
+ }
3843
+ }
3844
+ }
3831
3845
  const skipped = options.migrations.filter((migration) => appliedIds.has(migration.id)).map((migration) => migration.id);
3832
3846
  const pending = options.migrations.filter((migration) => !appliedIds.has(migration.id));
3833
3847
  const applied = [];