@@ -172,21 +172,28 @@ VALUES(4,
172
172
}
173
173
174
174
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).
176
176
// This is because the triggers are restructured in this version, and
177
177
// need to be re-created from scratch. Not dropping them can make it
178
178
// refer to tables or columns not existing anymore, which can case
179
179
// 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.
181
188
182
189
// language=SQLite
183
190
local_db
184
191
. exec_safe (
185
192
"\
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 = ' ';
190
197
191
198
ALTER TABLE ps_buckets RENAME TO ps_buckets_old;
192
199
ALTER TABLE ps_oplog RENAME TO ps_oplog_old;
0 commit comments