-
Notifications
You must be signed in to change notification settings - Fork 40
Storage version #487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Storage version #487
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
86b8c00
Add storage version.
rkistner 7869fa5
Always use versioned bucket names with the new storage version.
rkistner 8ba91e3
Fix some tests and imports.
rkistner 9ee46f2
Fix sync rule tests.
rkistner f292250
Fix more tests.
rkistner df9e2aa
Merge remote-tracking branch 'origin/main' into storage-version
rkistner 4cceebd
Rename STORAGE_VERSION_CONFIG.
rkistner 9f22f56
Merge remote-tracking branch 'origin/main' into storage-version
rkistner d6f27ab
Update hydrate method post merge.
rkistner f771dcd
Merge remote-tracking branch 'origin/main' into storage-version
rkistner 6999e38
Merge remote-tracking branch 'origin/main' into storage-version
rkistner a2402f8
Update tests.
rkistner 088de1c
Add a check for down migrations.
rkistner 3bc9fec
Add postgres migration.
rkistner db17781
Port storage version to Postgres storage.
rkistner 6109f85
Expand comments.
rkistner 4e8b465
Tweak Postgres migration script.
rkistner a7c299c
Enable versioned bucket ids on storage version 2; Test with version 1.
rkistner bc9bdef
Test with both storage versions.
rkistner 26e5c2d
Further mongodb test refactoring.
rkistner a584973
Truncate tables instead of running down migrations for postgres storage
rkistner 52564fa
Run postgres tests on multiple storage versions.
rkistner 0046203
Fix schema test.
rkistner bb1fbc0
Update storage tests.
rkistner 0414461
Add back timeout increases.
rkistner cfa3c5d
Update snapshots.
rkistner a353187
Fix migration tests.
rkistner 56ff6c0
Merge remote-tracking branch 'origin/main' into storage-version
rkistner f2bfba7
Change error code for storage version issues.
rkistner 255181b
Fix some tests.
rkistner 22b84bc
Remove obsolete snapshot.
rkistner b609604
Remove more obsolete snapshots.
rkistner 5042648
Changeset.
rkistner b69bf69
Fix imports.
rkistner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| '@powersync/service-module-postgres-storage': minor | ||
| '@powersync/service-module-mongodb-storage': minor | ||
| '@powersync/service-core-tests': minor | ||
| '@powersync/service-module-postgres': minor | ||
| '@powersync/service-module-mongodb': minor | ||
| '@powersync/service-core': minor | ||
| '@powersync/service-module-mssql': minor | ||
| '@powersync/service-module-mysql': minor | ||
| '@powersync/service-sync-rules': minor | ||
| '@powersync/service-errors': patch | ||
| --- | ||
|
|
||
| Introduce storage versions. |
44 changes: 44 additions & 0 deletions
44
modules/module-mongodb-storage/src/migrations/db/migrations/1770213298299-storage-version.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { migrations, storage as core_storage } from '@powersync/service-core'; | ||
| import * as mongo_storage from '../../../storage/storage-index.js'; | ||
| import { MongoStorageConfig } from '../../../types/types.js'; | ||
|
|
||
| export const up: migrations.PowerSyncMigrationFunction = async (context) => { | ||
| const { | ||
| service_context: { configuration } | ||
| } = context; | ||
| const db = mongo_storage.createPowerSyncMongo(configuration.storage as MongoStorageConfig); | ||
|
|
||
| try { | ||
| await db.sync_rules.updateMany( | ||
| { storage_version: { $exists: false } }, | ||
| { $set: { storage_version: core_storage.LEGACY_STORAGE_VERSION } } | ||
| ); | ||
| } finally { | ||
| await db.client.close(); | ||
| } | ||
| }; | ||
|
|
||
| export const down: migrations.PowerSyncMigrationFunction = async (context) => { | ||
| const { | ||
| service_context: { configuration } | ||
| } = context; | ||
|
|
||
| const db = mongo_storage.createPowerSyncMongo(configuration.storage as MongoStorageConfig); | ||
|
|
||
| try { | ||
| const newRules = await db.sync_rules | ||
| .find({ storage_version: { $gt: core_storage.LEGACY_STORAGE_VERSION } }) | ||
| .toArray(); | ||
| if (newRules.length > 0) { | ||
| throw new Error( | ||
| `Cannot revert migration due to newer storage versions in use: ${newRules.map((r) => `${r._id}: v${r.storage_version}`).join(', ')}` | ||
| ); | ||
| } | ||
| await db.sync_rules.updateMany( | ||
| { storage_version: core_storage.LEGACY_STORAGE_VERSION }, | ||
| { $unset: { storage_version: 1 } } | ||
| ); | ||
| } finally { | ||
| await db.client.close(); | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 25 additions & 3 deletions
28
modules/module-mongodb-storage/src/storage/implementation/MongoPersistedSyncRules.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,42 @@ | ||
| import { SyncConfigWithErrors, HydratedSyncRules, versionedHydrationState } from '@powersync/service-sync-rules'; | ||
| import { | ||
| CompatibilityOption, | ||
| DEFAULT_HYDRATION_STATE, | ||
| HydratedSyncRules, | ||
| HydrationState, | ||
| SyncConfigWithErrors, | ||
| versionedHydrationState | ||
| } from '@powersync/service-sync-rules'; | ||
|
|
||
| import { storage } from '@powersync/service-core'; | ||
|
|
||
| import { StorageConfig } from './models.js'; | ||
|
|
||
| export class MongoPersistedSyncRules implements storage.PersistedSyncRules { | ||
| public readonly slot_name: string; | ||
| public readonly hydrationState: HydrationState; | ||
|
|
||
| constructor( | ||
| public readonly id: number, | ||
| public readonly sync_rules: SyncConfigWithErrors, | ||
| public readonly checkpoint_lsn: string | null, | ||
| slot_name: string | null | ||
| slot_name: string | null, | ||
| public readonly storageConfig: StorageConfig | ||
| ) { | ||
| this.slot_name = slot_name ?? `powersync_${id}`; | ||
|
|
||
| if ( | ||
| storageConfig.versionedBuckets || | ||
| this.sync_rules.config.compatibility.isEnabled(CompatibilityOption.versionedBucketIds) | ||
| ) { | ||
| // For new sync config versions (using the new storage version), we always enable versioned bucket names. | ||
| // For older versions, this depends on the compatibility option. | ||
| this.hydrationState = versionedHydrationState(this.id); | ||
| } else { | ||
| this.hydrationState = DEFAULT_HYDRATION_STATE; | ||
| } | ||
| } | ||
|
|
||
| hydratedSyncRules(): HydratedSyncRules { | ||
| return this.sync_rules.config.hydrate({ hydrationState: versionedHydrationState(this.id) }); | ||
| return this.sync_rules.config.hydrate({ hydrationState: this.hydrationState }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
modules/module-mongodb-storage/test/src/__snapshots__/storage.test.ts.snap
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.