@tinycloud/sdk-services 3.2.3 → 3.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.
- package/dist/index.cjs +22 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +22 -8
- package/dist/index.js.map +1 -1
- package/dist/sql/index.cjs +22 -8
- package/dist/sql/index.cjs.map +1 -1
- package/dist/sql/index.js +22 -8
- package/dist/sql/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3652,17 +3652,31 @@ var SQLService = class extends BaseService {
|
|
|
3652
3652
|
}
|
|
3653
3653
|
async applyMigrationsOnDbUnlocked(dbName, options) {
|
|
3654
3654
|
return this.withTelemetry("migrations.apply", dbName, async () => {
|
|
3655
|
-
const
|
|
3655
|
+
const probe = await this.queryOnDb(
|
|
3656
3656
|
dbName,
|
|
3657
|
-
`SELECT
|
|
3658
|
-
[
|
|
3657
|
+
`SELECT name FROM sqlite_master WHERE type='table' AND name='${MIGRATIONS_TABLE}'`,
|
|
3658
|
+
[],
|
|
3659
3659
|
{ signal: options.signal }
|
|
3660
3660
|
);
|
|
3661
|
-
|
|
3662
|
-
if (!
|
|
3663
|
-
const appliedIds = new Set(
|
|
3664
|
-
|
|
3665
|
-
|
|
3661
|
+
let tableMissing = probe.ok ? probe.data.rows.length === 0 : probe.error.code === ErrorCodes.SQL_DATABASE_NOT_FOUND || isMissingTableError(probe.error.message);
|
|
3662
|
+
if (!probe.ok && !tableMissing) return probe;
|
|
3663
|
+
const appliedIds = /* @__PURE__ */ new Set();
|
|
3664
|
+
if (!tableMissing) {
|
|
3665
|
+
const listed = await this.queryOnDb(
|
|
3666
|
+
dbName,
|
|
3667
|
+
`SELECT id FROM ${MIGRATIONS_TABLE} WHERE namespace = ? ORDER BY applied_at, id`,
|
|
3668
|
+
[options.namespace],
|
|
3669
|
+
{ signal: options.signal }
|
|
3670
|
+
);
|
|
3671
|
+
tableMissing = !listed.ok && (listed.error.code === ErrorCodes.SQL_DATABASE_NOT_FOUND || isMissingTableError(listed.error.message));
|
|
3672
|
+
if (!listed.ok && !tableMissing) return listed;
|
|
3673
|
+
if (listed.ok) {
|
|
3674
|
+
for (const row of listed.data.rows) {
|
|
3675
|
+
const id = rowValue(row, 0);
|
|
3676
|
+
if (typeof id === "string") appliedIds.add(id);
|
|
3677
|
+
}
|
|
3678
|
+
}
|
|
3679
|
+
}
|
|
3666
3680
|
const skipped = options.migrations.filter((migration) => appliedIds.has(migration.id)).map((migration) => migration.id);
|
|
3667
3681
|
const pending = options.migrations.filter((migration) => !appliedIds.has(migration.id));
|
|
3668
3682
|
const applied = [];
|