Update migration system

This commit is contained in:
Raven Scott
2026-05-30 17:21:25 -04:00
parent 1ffdd12efb
commit 71207e77ba
7 changed files with 302 additions and 222 deletions
+9 -10
View File
@@ -632,22 +632,21 @@ See [test-scripts/README.md](../test-scripts/README.md) for more information abo
5. **Check status**: Use `sdk.db.replication.getStatus()` to monitor replication health.
6. **Version bumping**: Bump `version` in config.json when making incompatible schema changes (e.g., removing indexes, changing key fields). This creates a new replicated core topic; P2NS migrates local data from the previous version on startup.
6. **Version bumping**: Bump `version` in config.json when making incompatible schema changes (e.g., removing indexes, changing key fields). This creates a new replicated core topic; P2NS migrates local data from the cached version on startup.
7. **Schema migrations**: When bumping `version` in `config.json`, P2NS automatically copies all collection data from the previous version's Hypercore into the new one on startup. A manifest at `plugin-sites/{domain}/db/.p2ns-db-version.json` tracks the last migrated version.
7. **Schema migrations**: When bumping `version` in `config.json`, P2NS automatically copies all collection data from the previous version's Hypercore into the new one on startup. Migration progress is tracked locally in `cache/plugin-db-migration/{domain}/version.json` (gitignored), not in `config.json`.
- Bump `version` in `config.json` and set migration flags under `hyperdb`:
- Bump `version` in `config.json` only — no migration flags needed:
```json
"hyperdb": {
"previousVersion": "1.2.2",
"migrated": false,
...
{
"version": "1.0.10",
"hyperdb": { ... }
}
```
- Restart P2NS — data is copied once from `previousVersion` to the new core when that core has records; if there is nothing to copy, migration is **skipped** and `migrated` is still set to `true` (`previousVersion` stays in config for reference)
- On the next bump, update `previousVersion` to the version you are leaving (e.g. `1.4.1` → `1.4.2` with `"previousVersion": "1.4.1"`) and set `migrated` back to `false`
- Restart P2NS — if the cached version is lower than `config.json` version, data is copied once from the cached core into the new one; if there is nothing to copy, migration is **skipped** and the cache is updated to the new version
- On first boot (no cache file), P2NS seeds the cache from any legacy manifest or existing data, then runs migration if needed
- Coordinate the same version bump with all peers so replication uses the same core topic
- If upgrading from before auto-migration and data appears missing, add the old version to `hyperdb.versionHistory` once (e.g. `"versionHistory": ["1.2.1"]`) and `"migrated": false`
- For one-time recovery from very old installs, you can still add known prior versions to `hyperdb.versionHistory` in config (optional)
## Reference