Skip to content

Commit 59fe052

Browse files
committed
Drop views for the schema 5 migration.
1 parent eb82c46 commit 59fe052

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

crates/core/src/view_admin.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ CREATE TABLE IF NOT EXISTS ps_migration(id INTEGER PRIMARY KEY, down_migrations
149149
if current_version == 5 {
150150
down_sql.push(
151151
"\
152+
-- Drop all existing views (and triggers)
153+
SELECT powersync_drop_view(view.name)
154+
FROM sqlite_master view
155+
WHERE view.type = 'view'
156+
AND view.sql GLOB '*-- powersync-auto-generated';
157+
152158
ALTER TABLE ps_buckets RENAME TO ps_buckets_5;
153159
ALTER TABLE ps_oplog RENAME TO ps_oplog_5;
154160
@@ -326,6 +332,12 @@ INSERT INTO ps_migration(id, down_migrations)
326332
local_db
327333
.exec_safe(
328334
"\
335+
-- Drop all existing views (and triggers)
336+
SELECT powersync_drop_view(view.name)
337+
FROM sqlite_master view
338+
WHERE view.type = 'view'
339+
AND view.sql GLOB '*-- powersync-auto-generated';
340+
329341
ALTER TABLE ps_buckets RENAME TO ps_buckets_old;
330342
ALTER TABLE ps_oplog RENAME TO ps_oplog_old;
331343
@@ -414,10 +426,10 @@ fn powersync_init_impl(
414426
) -> Result<String, SQLiteError> {
415427
let local_db = ctx.db_handle();
416428

417-
powersync_migrate(ctx, 5)?;
418-
419429
setup_internal_views(local_db)?;
420430

431+
powersync_migrate(ctx, 5)?;
432+
421433
Ok(String::from(""))
422434
}
423435

0 commit comments

Comments
 (0)