@@ -335,6 +335,14 @@ END''',
335335
336336 setUp (() => db.execute ('SELECT powersync_init();' ));
337337
338+ test ('requires a transaction' , () {
339+ expect (
340+ () => db.execute (
341+ 'SELECT powersync_raw_table_migrate(?, ?)' , ['create' , syncName]),
342+ throwsA (isA <SqliteException >()),
343+ );
344+ });
345+
338346 group ('create' , () {
339347 void createUntypedItem (String id, Object ? json) {
340348 db.execute (
@@ -354,8 +362,10 @@ END''',
354362 db.execute (
355363 'CREATE TABLE greetings (id TEXT PRIMARY KEY, hello TEXT) STRICT;' );
356364
365+ db.execute ('BEGIN' );
357366 db.execute (
358367 'SELECT powersync_raw_table_migrate(?, ?)' , ['create' , syncName]);
368+ db.execute ('COMMIT' );
359369 expect (db.select ('select * from ps_untyped' ), isEmpty);
360370 expect (db.select ('select * from greetings' ), [
361371 {'id' : 'foo' , 'hello' : 'world' },
@@ -383,8 +393,10 @@ END''',
383393 db.execute (
384394 'CREATE TABLE greetings (id TEXT PRIMARY KEY, hello TEXT) STRICT;' );
385395
396+ db.execute ('BEGIN' );
386397 db.execute (
387398 'SELECT powersync_raw_table_migrate(?, ?)' , ['create' , syncName]);
399+ db.execute ('COMMIT' );
388400 expect (db.select ('select * from ps_untyped' ), isEmpty);
389401 expect (db.select ('select * from greetings' ), [
390402 {'id' : 'foo' , 'hello' : 'world' },
@@ -405,14 +417,16 @@ END''',
405417 'INSERT INTO greetings (id, hello, local) VALUES (?, ?, uuid())' ,
406418 ['id_1' , 'second' ],
407419 )
420+ ..execute ('BEGIN' )
408421 ..execute ('SELECT powersync_raw_table_migrate(?, ?)' , [
409422 'drop' ,
410423 json.encode ({
411424 'name' : syncName,
412425 'table_name' : 'greetings' ,
413426 'synced_columns' : ['hello' ]
414427 })
415- ]);
428+ ])
429+ ..execute ('COMMIT' );
416430
417431 expect (db.select ('select * from ps_untyped' ), [
418432 {'type' : 'synced_table' , 'id' : 'id_0' , 'data' : '{"hello":"first"}' },
@@ -425,8 +439,8 @@ END''',
425439 json.encode ({'name' : syncName, 'table_name' : 'greetings' });
426440
427441 db.execute ('SELECT powersync_replace_schema(?)' , [
428- json.encode (
429- singleRawTableSchema ( {'name' : syncName, 'table_name' : 'greetings' })),
442+ json.encode (singleRawTableSchema (
443+ {'name' : syncName, 'table_name' : 'greetings' })),
430444 ]);
431445 db.execute (
432446 'CREATE TABLE greetings (id TEXT PRIMARY KEY, hello TEXT) STRICT;' );
@@ -439,12 +453,21 @@ SELECT
439453''' , [tableJson]);
440454
441455 db
442- ..execute ('INSERT INTO ps_untyped (type, id, data) VALUES (?, ?, ?)' ,
443- [syncName, 'id_1' , json.encode ({'hello' : 'world' })])
444- ..execute ('INSERT INTO ps_untyped (type, id, data) VALUES (?, ?, ?)' ,
445- [syncName, 'id_2' , json.encode ({'hello' : 'again' })]);
456+ ..execute (
457+ 'INSERT INTO ps_untyped (type, id, data) VALUES (?, ?, ?)' , [
458+ syncName,
459+ 'id_1' ,
460+ json.encode ({'hello' : 'world' })
461+ ])
462+ ..execute (
463+ 'INSERT INTO ps_untyped (type, id, data) VALUES (?, ?, ?)' , [
464+ syncName,
465+ 'id_2' ,
466+ json.encode ({'hello' : 'again' })
467+ ]);
446468
447469 // create migration: ps_untyped -> raw table; triggers must not fire
470+ db.execute ('BEGIN' );
448471 db.execute (
449472 'SELECT powersync_raw_table_migrate(?, ?)' , ['create' , syncName]);
450473 expect (db.select ('SELECT * FROM ps_crud' ), isEmpty);
@@ -454,6 +477,7 @@ SELECT
454477 'drop' ,
455478 json.encode ({'name' : syncName, 'table_name' : 'greetings' }),
456479 ]);
480+ db.execute ('COMMIT' );
457481 expect (db.select ('SELECT * FROM ps_crud' ), isEmpty);
458482 });
459483 });
0 commit comments