@tinycloud/replica 0.2.2 → 0.2.3-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/replica.worker.js +22 -8
- package/dist/replica.worker.js.map +1 -1
- package/package.json +2 -2
package/dist/replica.worker.js
CHANGED
|
@@ -10159,17 +10159,31 @@ var SQLService = class extends BaseService {
|
|
|
10159
10159
|
}
|
|
10160
10160
|
async applyMigrationsOnDbUnlocked(dbName, options) {
|
|
10161
10161
|
return this.withTelemetry("migrations.apply", dbName, async () => {
|
|
10162
|
-
const
|
|
10162
|
+
const probe = await this.queryOnDb(
|
|
10163
10163
|
dbName,
|
|
10164
|
-
`SELECT
|
|
10165
|
-
[
|
|
10164
|
+
`SELECT name FROM sqlite_master WHERE type='table' AND name='${MIGRATIONS_TABLE}'`,
|
|
10165
|
+
[],
|
|
10166
10166
|
{ signal: options.signal }
|
|
10167
10167
|
);
|
|
10168
|
-
|
|
10169
|
-
if (!
|
|
10170
|
-
const appliedIds = new Set(
|
|
10171
|
-
|
|
10172
|
-
|
|
10168
|
+
let tableMissing = probe.ok ? probe.data.rows.length === 0 : probe.error.code === ErrorCodes.SQL_DATABASE_NOT_FOUND || isMissingTableError(probe.error.message);
|
|
10169
|
+
if (!probe.ok && !tableMissing) return probe;
|
|
10170
|
+
const appliedIds = /* @__PURE__ */ new Set();
|
|
10171
|
+
if (!tableMissing) {
|
|
10172
|
+
const listed = await this.queryOnDb(
|
|
10173
|
+
dbName,
|
|
10174
|
+
`SELECT id FROM ${MIGRATIONS_TABLE} WHERE namespace = ? ORDER BY applied_at, id`,
|
|
10175
|
+
[options.namespace],
|
|
10176
|
+
{ signal: options.signal }
|
|
10177
|
+
);
|
|
10178
|
+
tableMissing = !listed.ok && (listed.error.code === ErrorCodes.SQL_DATABASE_NOT_FOUND || isMissingTableError(listed.error.message));
|
|
10179
|
+
if (!listed.ok && !tableMissing) return listed;
|
|
10180
|
+
if (listed.ok) {
|
|
10181
|
+
for (const row of listed.data.rows) {
|
|
10182
|
+
const id = rowValue(row, 0);
|
|
10183
|
+
if (typeof id === "string") appliedIds.add(id);
|
|
10184
|
+
}
|
|
10185
|
+
}
|
|
10186
|
+
}
|
|
10173
10187
|
const skipped = options.migrations.filter((migration) => appliedIds.has(migration.id)).map((migration) => migration.id);
|
|
10174
10188
|
const pending = options.migrations.filter((migration) => !appliedIds.has(migration.id));
|
|
10175
10189
|
const applied = [];
|