@@ -17,14 +17,12 @@ Future<void> initializeRawTablesSchema(PowerSyncDatabase db) async {
1717 }
1818
1919 if (schemaVersion > latestSchemaVersion) {
20- throw Exception (
21- "Database is in a newer version than expected ($schemaVersion )" );
20+ throw Exception ("Database is in a newer version than expected ($schemaVersion )" );
2221 }
2322
2423 print ("Migrating from custom db schema version $schemaVersion to $latestSchemaVersion " );
2524 for (var i = schemaVersion; i < latestSchemaVersion; i++ ) {
26- assert (_migrationsMap.containsKey (i),
27- 'Migrations map is missing migration from version $i ' );
25+ assert (_migrationsMap.containsKey (i), 'Migrations map is missing migration from version $i ' );
2826 await _migrationsMap[i]! (ctx);
2927 }
3028
@@ -57,34 +55,29 @@ CREATE TABLE IF NOT EXISTS $listsRawTable(
5755
5856Future <void > _createInsertListTriggers (SqliteWriteContext ctx) async {
5957 final table = listsRawTable;
60- final dataJsonExpr = 'json(${ _buildJsonObjectExpression (
58+ final dataJsonExpr = _buildJsonObjectExpression (
6159 columns: [
6260 'created_at' ,
6361 'name' ,
6462 'owner_id' ,
6563 ],
6664 columnPrefix: 'NEW' ,
67- )})' ;
65+ );
6866
6967 await ctx.execute ('''
7068CREATE TRIGGER IF NOT EXISTS ${table }_insert
7169AFTER INSERT ON $table
7270FOR EACH ROW
73- WHEN NOT powersync_in_sync_operation()
7471BEGIN
75- INSERT INTO powersync_crud_(data) VALUES(json_object('op', 'PUT', 'type', '$table ', 'id', NEW.id, 'data', $dataJsonExpr ));
76- INSERT OR IGNORE INTO ps_updated_rows(row_type, row_id) VALUES('$table ', NEW.id);
77- INSERT OR REPLACE INTO ps_buckets(name, last_op, target_op) VALUES('\$ local', 0, 9223372036854775807);
72+ INSERT INTO powersync_crud (op, id, type, data) VALUES('PUT',NEW.id, '$table ', $dataJsonExpr );
7873END;
7974''' );
8075}
8176
82- String _buildJsonObjectExpression (
83- {required List <String > columns, String ? columnPrefix}) {
77+ String _buildJsonObjectExpression ({required List <String > columns, String ? columnPrefix}) {
8478 final list = columns.map ((columnName) {
8579 final String key = "'$columnName '" ;
86- final String value =
87- columnPrefix != null ? '$columnPrefix .$columnName ' : columnName;
80+ final String value = columnPrefix != null ? '$columnPrefix .$columnName ' : columnName;
8881 return '$key , $value ' ;
8982 }).join (', ' );
9083
@@ -151,8 +144,7 @@ Future<void> _setupSchemaVersionTable(PowerSyncDatabase db) async {
151144 ''' );
152145
153146 // If no version is recorded, insert the initial version.
154- final result =
155- await ctx.get ('SELECT COUNT(*) as count FROM $_versionTable ;' );
147+ final result = await ctx.get ('SELECT COUNT(*) as count FROM $_versionTable ;' );
156148 final count = result['count' ] as int ;
157149 if (count == 0 ) {
158150 await ctx.execute ('INSERT INTO $_versionTable (version) VALUES (0);' );
0 commit comments