Skip to content

Commit b8963b9

Browse files
committed
test for table not in schema scenario
1 parent 4a380a3 commit b8963b9

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

crates/core/src/schema/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ fn raw_table_migration(
159159
// Generate an INSERT INTO ps_untyped with a SELECT source transforming existing
160160
// rows into JSON objects.
161161
let mut buffer = SqlBuffer::new();
162-
let fragment = table_columns_to_json_object(&local_table_name, &as_schema_table)?;
162+
let fragment = table_columns_to_json_object(local_table_name, &as_schema_table)?;
163163
buffer.push_str("INSERT INTO ps_untyped (type, id, data) SELECT ?, id, ");
164164
buffer.push_str(&fragment);
165165
buffer.push_str(" FROM ");

dart/test/schema_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,20 @@ END''',
392392
{'id': 'bar', 'hello': 'again'},
393393
]);
394394
});
395+
396+
test('errors when table is not in schema', () {
397+
db.execute('SELECT powersync_replace_schema(?)', [
398+
json.encode(singleRawTableSchema(
399+
{'name': syncName, 'table_name': 'greetings'})),
400+
]);
401+
402+
db.execute('BEGIN');
403+
expect(
404+
() => db.execute('SELECT powersync_raw_table_migrate(?, ?)',
405+
['create', 'unknown_table']),
406+
throwsA(isA<SqliteException>()),
407+
);
408+
});
395409
});
396410

397411
test('drop', () {
@@ -421,6 +435,7 @@ END''',
421435
{'type': 'synced_table', 'id': 'id_0', 'data': '{"hello":"first"}'},
422436
{'type': 'synced_table', 'id': 'id_1', 'data': '{"hello":"second"}'},
423437
]);
438+
expect(db.select('select * from greetings'), isEmpty);
424439
});
425440

426441
test('crud triggers are not invoked during migration', () {

0 commit comments

Comments
 (0)