@@ -5,6 +5,7 @@ import 'package:test/test.dart';
55
66import 'utils/native_test_utils.dart' ;
77import 'utils/migration_fixtures.dart' as fixtures;
8+ import 'utils/fix_035_fixtures.dart' as fix035;
89import 'utils/schema.dart' ;
910
1011void main () {
@@ -175,5 +176,40 @@ void main() {
175176 '${fixtures .expectedState [3 ]!.replaceAll (RegExp (r';INSERT INTO ps_migration.*' ), '' ).trim ()}\n ${fixtures .schemaDown3 .trim ()}' ;
176177 expect (schema, equals (expected));
177178 });
179+
180+ test ('migrate from 5 with broken data' , () async {
181+ var tableSchema = {
182+ 'tables' : [
183+ {
184+ 'name' : 'lists' ,
185+ 'columns' : [
186+ {'name' : 'description' , 'type' : 'TEXT' }
187+ ]
188+ },
189+ {
190+ 'name' : 'todos' ,
191+ 'columns' : [
192+ {'name' : 'description' , 'type' : 'TEXT' }
193+ ]
194+ }
195+ ]
196+ };
197+ db.select ('select powersync_init()' );
198+ db.select (
199+ 'select powersync_replace_schema(?)' , [jsonEncode (tableSchema)]);
200+
201+ db.select ('select powersync_test_migration(5)' );
202+ db.execute (fix035.dataBroken);
203+
204+ db.select ('select powersync_init()' );
205+ final data = getData (db);
206+ expect (data, equals (fix035.dataMigrated.trim ()));
207+
208+ db.select ('insert into powersync_operations(op, data) values(?, ?)' ,
209+ ['sync_local' , '' ]);
210+
211+ final data2 = getData (db);
212+ expect (data2, equals (fix035.dataFixed.trim ()));
213+ });
178214 });
179215}
0 commit comments