From d52637a3284c631ed637e03d9d25697012ea97b2 Mon Sep 17 00:00:00 2001 From: Ralf Kistner Date: Mon, 10 Nov 2025 18:18:02 +0200 Subject: [PATCH 1/2] Duplicate migration to fix issues with migration ordering. --- .../1752661449910-connection-reporting.ts | 36 +----------- .../1762790715147-connection-reporting2.ts | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+), 35 deletions(-) create mode 100644 modules/module-mongodb-storage/src/migrations/db/migrations/1762790715147-connection-reporting2.ts diff --git a/modules/module-mongodb-storage/src/migrations/db/migrations/1752661449910-connection-reporting.ts b/modules/module-mongodb-storage/src/migrations/db/migrations/1752661449910-connection-reporting.ts index a74c35291..b05a14ab5 100644 --- a/modules/module-mongodb-storage/src/migrations/db/migrations/1752661449910-connection-reporting.ts +++ b/modules/module-mongodb-storage/src/migrations/db/migrations/1752661449910-connection-reporting.ts @@ -6,41 +6,7 @@ export const up: migrations.PowerSyncMigrationFunction = async (context) => { const { service_context: { configuration } } = context; - const db = storage.createPowerSyncMongo(configuration.storage as MongoStorageConfig); - - try { - await db.createConnectionReportingCollection(); - - await db.connection_report_events.createIndex( - { - connected_at: 1, - jwt_exp: 1, - disconnected_at: 1 - }, - { name: 'connection_list_index' } - ); - - await db.connection_report_events.createIndex( - { - user_id: 1 - }, - { name: 'connection_user_id_index' } - ); - await db.connection_report_events.createIndex( - { - client_id: 1 - }, - { name: 'connection_client_id_index' } - ); - await db.connection_report_events.createIndex( - { - sdk: 1 - }, - { name: 'connection_index' } - ); - } finally { - await db.client.close(); - } + // No-op - moved to 1762790715147-connection-reporting2 }; export const down: migrations.PowerSyncMigrationFunction = async (context) => { diff --git a/modules/module-mongodb-storage/src/migrations/db/migrations/1762790715147-connection-reporting2.ts b/modules/module-mongodb-storage/src/migrations/db/migrations/1762790715147-connection-reporting2.ts new file mode 100644 index 000000000..a74c35291 --- /dev/null +++ b/modules/module-mongodb-storage/src/migrations/db/migrations/1762790715147-connection-reporting2.ts @@ -0,0 +1,58 @@ +import { migrations } from '@powersync/service-core'; +import * as 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 = storage.createPowerSyncMongo(configuration.storage as MongoStorageConfig); + + try { + await db.createConnectionReportingCollection(); + + await db.connection_report_events.createIndex( + { + connected_at: 1, + jwt_exp: 1, + disconnected_at: 1 + }, + { name: 'connection_list_index' } + ); + + await db.connection_report_events.createIndex( + { + user_id: 1 + }, + { name: 'connection_user_id_index' } + ); + await db.connection_report_events.createIndex( + { + client_id: 1 + }, + { name: 'connection_client_id_index' } + ); + await db.connection_report_events.createIndex( + { + sdk: 1 + }, + { name: 'connection_index' } + ); + } finally { + await db.client.close(); + } +}; + +export const down: migrations.PowerSyncMigrationFunction = async (context) => { + const { + service_context: { configuration } + } = context; + + const db = storage.createPowerSyncMongo(configuration.storage as MongoStorageConfig); + + try { + await db.db.dropCollection('connection_report_events'); + } finally { + await db.client.close(); + } +}; From a0bbcca9db4d5e6c8b2d3bc7f6d93a3ba7b50ac4 Mon Sep 17 00:00:00 2001 From: Ralf Kistner Date: Mon, 10 Nov 2025 18:22:35 +0200 Subject: [PATCH 2/2] Changeset. --- .changeset/gorgeous-ligers-leave.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/gorgeous-ligers-leave.md diff --git a/.changeset/gorgeous-ligers-leave.md b/.changeset/gorgeous-ligers-leave.md new file mode 100644 index 000000000..df2aacd83 --- /dev/null +++ b/.changeset/gorgeous-ligers-leave.md @@ -0,0 +1,7 @@ +--- +'@powersync/service-module-mongodb-storage': patch +'@powersync/service-core': patch +'@powersync/service-image': patch +--- + +[MongoDB storage] Fix migration for indexes on connection_report_events.