Skip to content

Commit 44dac47

Browse files
authored
Merge pull request #48 from powersync-ja/fix-triggers-migration
Fix view migration issue
2 parents 99e4850 + 44d819f commit 44dac47

File tree

10 files changed

+60
-18
lines changed

10 files changed

+60
-18
lines changed

.github/workflows/macos.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
build_macOS_x64:
2323
name: Building macOS x64
24-
runs-on: macos-12
24+
runs-on: macos-14
2525
steps:
2626
- uses: actions/checkout@v3
2727
with:

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ jobs:
244244
publish_macOS_x64:
245245
name: Publish macOS x64
246246
needs: [draft_release]
247-
runs-on: macos-12
247+
runs-on: macos-14
248248
steps:
249249
- uses: actions/checkout@v3
250250
with:

Cargo.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ inherits = "release"
2424
inherits = "wasm"
2525

2626
[workspace.package]
27-
version = "0.3.6"
27+
version = "0.3.7"
2828
edition = "2021"
2929
authors = ["JourneyApps"]
3030
keywords = ["sqlite", "powersync"]

android/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = "co.powersync"
9-
version = "0.3.6"
9+
version = "0.3.7"
1010
description = "PowerSync Core SQLite Extension"
1111

1212
repositories {

android/src/prefab/prefab.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"name": "powersync_sqlite_core",
33
"schema_version": 2,
44
"dependencies": [],
5-
"version": "0.3.6"
5+
"version": "0.3.7"
66
}

crates/core/src/migrations.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -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
191198
ALTER TABLE ps_buckets RENAME TO ps_buckets_old;
192199
ALTER TABLE ps_oplog RENAME TO ps_oplog_old;

dart/test/migration_test.dart

+35
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,40 @@ void main() {
211211
final data2 = getData(db);
212212
expect(data2, equals(fix035.dataFixed.trim()));
213213
});
214+
215+
/// Here we start with a schema from fixtures on db version 3
216+
test('schema 3 -> 5 with custom triggers', () async {
217+
db.execute(fixtures.expectedState[3]!);
218+
db.execute(fixtures.schema3);
219+
// This is a contrived example, but gives us a trigger
220+
// that references the "lists" view, affecting migrations.
221+
db.execute('''
222+
create trigger t1 after delete on ps_data__lists begin
223+
insert into lists(id, description) values(OLD.id, 'deleted');
224+
end''');
225+
226+
var tableSchema = {
227+
'tables': [
228+
{
229+
'name': 'lists',
230+
'columns': [
231+
{'name': 'description', 'type': 'TEXT'}
232+
]
233+
}
234+
]
235+
};
236+
db.select('select powersync_init()');
237+
db.select(
238+
'select powersync_replace_schema(?)', [jsonEncode(tableSchema)]);
239+
240+
final schema = getSchema(db);
241+
final expected =
242+
'''${fixtures.finalState.replaceAll(RegExp(r';INSERT INTO ps_migration.*'), '').trim()}
243+
${fixtures.schema5.trim()}
244+
;CREATE TRIGGER t1 after delete on ps_data__lists begin
245+
insert into lists(id, description) values(OLD.id, \'deleted\');
246+
end''';
247+
expect(schema, equals(expected));
248+
});
214249
});
215250
}

powersync-sqlite-core.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'powersync-sqlite-core'
3-
s.version = '0.3.6'
3+
s.version = '0.3.7'
44
s.summary = 'PowerSync SQLite Extension'
55
s.description = <<-DESC
66
PowerSync extension for SQLite.

tool/build_xcframework.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ function createXcframework() {
2828
<key>MinimumOSVersion</key>
2929
<string>11.0</string>
3030
<key>CFBundleVersion</key>
31-
<string>0.3.6</string>
31+
<string>0.3.7</string>
3232
<key>CFBundleShortVersionString</key>
33-
<string>0.3.6</string>
33+
<string>0.3.7</string>
3434
</dict>
3535
</plist>
3636
EOF

0 commit comments

Comments
 (0)