File tree Expand file tree Collapse file tree 2 files changed +45
-22
lines changed
modules/module-postgres-storage/src/migrations/scripts Expand file tree Collapse file tree 2 files changed +45
-22
lines changed Original file line number Diff line number Diff line change @@ -128,28 +128,6 @@ export const up: migrations.PowerSyncMigrationFunction = async (context) => {
128128 CONSTRAINT unique_user_sync PRIMARY KEY (user_id, sync_rules_id)
129129 );
130130 ` . execute ( ) ;
131-
132- await db . sql `
133- CREATE TABLE sdk_report_events (
134- id TEXT PRIMARY KEY,
135- user_agent TEXT NOT NULL,
136- client_id TEXT NOT NULL,
137- user_id TEXT NOT NULL,
138- sdk TEXT NOT NULL,
139- jwt_exp TIMESTAMP WITH TIME ZONE,
140- connect_at TIMESTAMP WITH TIME ZONE NOT NULL,
141- disconnect_at TIMESTAMP WITH TIME ZONE,
142- CONSTRAINT unique_user_client_connect UNIQUE (user_id, client_id, connect_at)
143- )
144- ` . execute ( ) ;
145-
146- await db . sql ` CREATE INDEX sdk_list_index ON sdk_report_events (connect_at, jwt_exp, disconnect_at) ` . execute ( ) ;
147-
148- await db . sql ` CREATE INDEX sdk_user_id_index ON sdk_report_events (user_id)` . execute ( ) ;
149-
150- await db . sql ` CREATE INDEX sdk_client_id_index ON sdk_report_events (client_id)` . execute ( ) ;
151-
152- await db . sql ` CREATE INDEX sdk_index ON sdk_report_events (sdk)` . execute ( ) ;
153131 } ) ;
154132} ;
155133
Original file line number Diff line number Diff line change 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+ await db . sql `
13+ CREATE TABLE IF NOT EXISTS sdk_report_events (
14+ id TEXT PRIMARY KEY,
15+ user_agent TEXT NOT NULL,
16+ client_id TEXT NOT NULL,
17+ user_id TEXT NOT NULL,
18+ sdk TEXT NOT NULL,
19+ jwt_exp TIMESTAMP WITH TIME ZONE,
20+ connect_at TIMESTAMP WITH TIME ZONE NOT NULL,
21+ disconnect_at TIMESTAMP WITH TIME ZONE,
22+ )
23+ ` . execute ( ) ;
24+
25+ await db . sql `
26+ CREATE INDEX IF NOT EXISTS sdk_list_index ON sdk_report_events (connect_at, jwt_exp, disconnect_at)
27+ ` . execute ( ) ;
28+
29+ await db . sql `CREATE INDEX IF NOT EXISTS sdk_user_id_index ON sdk_report_events (user_id)` . execute ( ) ;
30+
31+ await db . sql `CREATE INDEX IF NOT EXISTS sdk_client_id_index ON sdk_report_events (client_id)` . execute ( ) ;
32+
33+ await db . sql `CREATE INDEX IF NOT EXISTS sdk_index ON sdk_report_events (sdk)` . execute ( ) ;
34+ } ) ;
35+ } ;
36+
37+ export const down : migrations . PowerSyncMigrationFunction = async ( context ) => {
38+ const {
39+ service_context : { configuration }
40+ } = context ;
41+ await using client = openMigrationDB ( configuration . storage ) ;
42+ client . lockConnection ( async ( db ) => {
43+ await db . sql `DROP TABLE IF EXISTS sdk_report_events` . execute ( ) ;
44+ } ) ;
45+ } ;
You can’t perform that action at this time.
0 commit comments