@@ -172,28 +172,21 @@ VALUES(4,
172
172
}
173
173
174
174
if current_version < 5 && target_version >= 5 {
175
- // Start by dropping all triggers on views (but not views tables).
175
+ // Start by dropping all existing views and triggers (but not 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
- //
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.
180
+ // The same applies for the down migration.
188
181
189
182
// language=SQLite
190
183
local_db
191
184
. exec_safe (
192
185
"\
193
- UPDATE powersync_views SET
194
- delete_trigger_sql = '',
195
- update_trigger_sql = '',
196
- insert_trigger_sql = ' ';
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 ';
197
190
198
191
ALTER TABLE ps_buckets RENAME TO ps_buckets_old;
199
192
ALTER TABLE ps_oplog RENAME TO ps_oplog_old;
0 commit comments