Skip to content

Commit c6bdb4f

Browse files
authored
[MongoDB Storage] Duplicate migration to fix issues with migration ordering (#391)
* Duplicate migration to fix issues with migration ordering. * Changeset.
1 parent 15dfacd commit c6bdb4f

File tree

3 files changed

+66
-35
lines changed

3 files changed

+66
-35
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@powersync/service-module-mongodb-storage': patch
3+
'@powersync/service-core': patch
4+
'@powersync/service-image': patch
5+
---
6+
7+
[MongoDB storage] Fix migration for indexes on connection_report_events.

modules/module-mongodb-storage/src/migrations/db/migrations/1752661449910-connection-reporting.ts

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,7 @@ export const up: migrations.PowerSyncMigrationFunction = async (context) => {
66
const {
77
service_context: { configuration }
88
} = context;
9-
const db = storage.createPowerSyncMongo(configuration.storage as MongoStorageConfig);
10-
11-
try {
12-
await db.createConnectionReportingCollection();
13-
14-
await db.connection_report_events.createIndex(
15-
{
16-
connected_at: 1,
17-
jwt_exp: 1,
18-
disconnected_at: 1
19-
},
20-
{ name: 'connection_list_index' }
21-
);
22-
23-
await db.connection_report_events.createIndex(
24-
{
25-
user_id: 1
26-
},
27-
{ name: 'connection_user_id_index' }
28-
);
29-
await db.connection_report_events.createIndex(
30-
{
31-
client_id: 1
32-
},
33-
{ name: 'connection_client_id_index' }
34-
);
35-
await db.connection_report_events.createIndex(
36-
{
37-
sdk: 1
38-
},
39-
{ name: 'connection_index' }
40-
);
41-
} finally {
42-
await db.client.close();
43-
}
9+
// No-op - moved to 1762790715147-connection-reporting2
4410
};
4511

4612
export const down: migrations.PowerSyncMigrationFunction = async (context) => {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { migrations } from '@powersync/service-core';
2+
import * as storage from '../../../storage/storage-index.js';
3+
import { MongoStorageConfig } from '../../../types/types.js';
4+
5+
export const up: migrations.PowerSyncMigrationFunction = async (context) => {
6+
const {
7+
service_context: { configuration }
8+
} = context;
9+
const db = storage.createPowerSyncMongo(configuration.storage as MongoStorageConfig);
10+
11+
try {
12+
await db.createConnectionReportingCollection();
13+
14+
await db.connection_report_events.createIndex(
15+
{
16+
connected_at: 1,
17+
jwt_exp: 1,
18+
disconnected_at: 1
19+
},
20+
{ name: 'connection_list_index' }
21+
);
22+
23+
await db.connection_report_events.createIndex(
24+
{
25+
user_id: 1
26+
},
27+
{ name: 'connection_user_id_index' }
28+
);
29+
await db.connection_report_events.createIndex(
30+
{
31+
client_id: 1
32+
},
33+
{ name: 'connection_client_id_index' }
34+
);
35+
await db.connection_report_events.createIndex(
36+
{
37+
sdk: 1
38+
},
39+
{ name: 'connection_index' }
40+
);
41+
} finally {
42+
await db.client.close();
43+
}
44+
};
45+
46+
export const down: migrations.PowerSyncMigrationFunction = async (context) => {
47+
const {
48+
service_context: { configuration }
49+
} = context;
50+
51+
const db = storage.createPowerSyncMongo(configuration.storage as MongoStorageConfig);
52+
53+
try {
54+
await db.db.dropCollection('connection_report_events');
55+
} finally {
56+
await db.client.close();
57+
}
58+
};

0 commit comments

Comments
 (0)