@@ -172,21 +172,28 @@ VALUES(4,
172172 }
173173
174174 if current_version < 5 && target_version >= 5 {
175- // Start by dropping all existing views and triggers (but not tables).
175+ // Start by dropping all triggers on views (but not views tables).
176176 // This is because the triggers are restructured in this version, and
177177 // need to be re-created from scratch. Not dropping them can make it
178178 // refer to tables or columns not existing anymore, which can case
179179 // issues later on.
180- // The same applies for the down migration.
180+ //
181+ // Similarly, dropping the views themselves can cause issues with
182+ // user-defined triggers that refer to them.
183+ //
184+ // The same applies for the down migration, except there we do drop
185+ // the views, since we cannot use the `powersync_views` view.
186+ // Down migrations are less common, so we're okay about that breaking
187+ // in some cases.
181188
182189 // language=SQLite
183190 local_db
184191 . exec_safe (
185192 "\
186- SELECT powersync_drop_view(view.name)
187- FROM sqlite_master view
188- WHERE view.type = 'view'
189- AND view.sql GLOB '*-- powersync-auto-generated ';
193+ UPDATE powersync_views SET
194+ delete_trigger_sql = '',
195+ update_trigger_sql = '',
196+ insert_trigger_sql = ' ';
190197
191198ALTER TABLE ps_buckets RENAME TO ps_buckets_old;
192199ALTER TABLE ps_oplog RENAME TO ps_oplog_old;
0 commit comments