Skip to content

Commit fe1bc2b

Browse files
committed
Add migration to fix the issue.
1 parent 8383d63 commit fe1bc2b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { migrations } from '@powersync/service-core';
2+
3+
import { openMigrationDB } from '../migration-utils.js';
4+
5+
export const up: migrations.PowerSyncMigrationFunction = async (context) => {
6+
const {
7+
service_context: { configuration }
8+
} = context;
9+
await using client = openMigrationDB(configuration.storage);
10+
11+
await client.transaction(async (db) => {
12+
// This ensures that op_id_sequence is initialized, so that
13+
// SELECT nextval('op_id_sequence')
14+
// is always greater than
15+
// SELECT LAST_VALUE FROM op_id_sequence
16+
// Without initializing, there is a case where last_value = 1, is_called = false, and the next call to nextval is also 1.
17+
// This call is harmless if the sequence was already initialized - it would only increment the sequence by 1.
18+
await db.sql`
19+
SELECT
20+
nextval('op_id_sequence');
21+
`.execute();
22+
});
23+
};
24+
25+
export const down: migrations.PowerSyncMigrationFunction = async (context) => {
26+
// No-op - no need to revert the initialization when migrating down.
27+
};

0 commit comments

Comments
 (0)