Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/gorgeous-ligers-leave.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
};