@lobb-js/core 0.26.0 → 0.26.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lobb-js/core",
3
3
  "license": "UNLICENSED",
4
- "version": "0.26.0",
4
+ "version": "0.26.1",
5
5
  "type": "module",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -35,11 +35,27 @@ export class DatabaseSyncManager {
35
35
  // Startup tasks run first — applies any idempotent DB fixes before schema reading begins.
36
36
  await runCoreDbSetup();
37
37
 
38
+ const dbSchemaDiff = await this.getDbDifferences(specificColleciton);
39
+
40
+ // Pass 1: additive ops only (add-collection, add-field) — always safe, no data loss possible.
41
+ // Running these before migrations means any new collection defined in config already exists
42
+ // when migration code tries to seed it.
43
+ const additiveOps = dbSchemaDiff.filter(
44
+ (op) => op.op === "add-collection" || op.op === "add-field",
45
+ );
46
+ await this.applyDbSchemaDiff(additiveOps, forceSync);
47
+
48
+ // Migrations run after additive schema changes so they can safely insert into new collections.
38
49
  const migrationsManager = new MigrationsManager();
39
50
  await migrationsManager.init();
40
51
 
41
- const dbSchemaDiff = await this.getDbDifferences(specificColleciton);
42
- await this.applyDbSchemaDiff(dbSchemaDiff, forceSync);
52
+ // Pass 2: everything else (remove-collection, remove-field, alter-field, indexes).
53
+ // Destructive ops run after migrations so a migration can clear data before applyDbSchemaDiff
54
+ // would otherwise refuse to drop a column/table that still has rows.
55
+ const remainingOps = dbSchemaDiff.filter(
56
+ (op) => op.op !== "add-collection" && op.op !== "add-field",
57
+ );
58
+ await this.applyDbSchemaDiff(remainingOps, forceSync);
43
59
  }
44
60
 
45
61
  private async applyDbSchemaDiff(ops: SchemaDiffOp[], forceSync: boolean) {