@hatk/hatk 0.0.1-alpha.52 → 0.0.1-alpha.53
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/database/db.js +13 -16
- package/package.json +1 -1
package/dist/database/db.js
CHANGED
|
@@ -214,13 +214,16 @@ function buildChildExpectedCols(columns) {
|
|
|
214
214
|
}
|
|
215
215
|
export async function migrateSchema(tableSchemas) {
|
|
216
216
|
const changes = [];
|
|
217
|
+
const newCollections = new Set();
|
|
217
218
|
for (const schema of tableSchemas) {
|
|
218
219
|
if (schema.columns.length === 0)
|
|
219
220
|
continue; // generic JSON storage, skip
|
|
220
221
|
const tableName = schema.collection;
|
|
221
222
|
const existingCols = await getExistingColumns(tableName);
|
|
222
|
-
if (existingCols.size === 0)
|
|
223
|
+
if (existingCols.size === 0) {
|
|
224
|
+
newCollections.add(schema.collection);
|
|
223
225
|
continue; // table just created, nothing to migrate
|
|
226
|
+
}
|
|
224
227
|
// Expected columns: base columns (uri, cid, did, indexed_at) + schema columns
|
|
225
228
|
const expectedCols = new Map();
|
|
226
229
|
expectedCols.set('uri', 'TEXT');
|
|
@@ -281,22 +284,16 @@ export async function migrateSchema(tableSchemas) {
|
|
|
281
284
|
if (changes.length > 0) {
|
|
282
285
|
await applyMigrationChanges(changes);
|
|
283
286
|
}
|
|
284
|
-
//
|
|
285
|
-
//
|
|
286
|
-
|
|
287
|
-
if (
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if (!row) {
|
|
294
|
-
await run(`UPDATE _repos SET status = 'pending' WHERE status = 'active'`);
|
|
295
|
-
emit('migration', 'new_collection', { collection: schema.collection });
|
|
296
|
-
break; // only need to mark once
|
|
297
|
-
}
|
|
287
|
+
// Trigger backfill only for genuinely new collections (tables created this startup)
|
|
288
|
+
// Previously this checked ALL empty tables, which caused infinite resync loops
|
|
289
|
+
// for collections that are legitimately empty (e.g. blocks when nobody has blocked)
|
|
290
|
+
if (newCollections.size > 0) {
|
|
291
|
+
const [hasRepos] = await all(`SELECT 1 FROM _repos LIMIT 1`);
|
|
292
|
+
if (hasRepos) {
|
|
293
|
+
await run(`UPDATE _repos SET status = 'pending' WHERE status = 'active'`);
|
|
294
|
+
for (const collection of newCollections) {
|
|
295
|
+
emit('migration', 'new_collection', { collection });
|
|
298
296
|
}
|
|
299
|
-
catch { }
|
|
300
297
|
}
|
|
301
298
|
}
|
|
302
299
|
return changes;
|