Skip to content

Commit c6ffee3

Browse files
committed
Invert local_only_columns filter
1 parent 0ae8d98 commit c6ffee3

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

crates/core/src/schema/raw_table.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl InferredTableStructure {
2323
pub fn read_from_database(
2424
table_name: &str,
2525
db: impl Connection,
26-
ignored_local_columns: &ColumnFilter,
26+
synced_columns: &Option<ColumnFilter>,
2727
) -> Result<Option<Self>, PowerSyncError> {
2828
let stmt = db.prepare_v2("select name from pragma_table_info(?)")?;
2929
stmt.bind_text(1, table_name, Destructor::STATIC)?;
@@ -35,7 +35,11 @@ impl InferredTableStructure {
3535
let name = stmt.column_text(0)?;
3636
if name == "id" {
3737
has_id_column = true;
38-
} else if !ignored_local_columns.matches(name) {
38+
} else if let Some(filter) = synced_columns
39+
&& !filter.matches(name)
40+
{
41+
// This column isn't part of the synced columns, skip.
42+
} else {
3943
columns.push(name.to_string());
4044
}
4145
}
@@ -64,9 +68,9 @@ pub fn generate_raw_table_trigger(
6468
return Err(PowerSyncError::argument_error("Table has no local name"));
6569
};
6670

67-
let local_only_columns = &table.schema.local_only_columns;
71+
let synced_columns = &table.schema.synced_columns;
6872
let Some(resolved_table) =
69-
InferredTableStructure::read_from_database(local_table_name, db, local_only_columns)?
73+
InferredTableStructure::read_from_database(local_table_name, db, synced_columns)?
7074
else {
7175
return Err(PowerSyncError::argument_error(format!(
7276
"Could not find {} in local schema",
@@ -85,10 +89,10 @@ pub fn generate_raw_table_trigger(
8589
// Skip the trigger for writes during sync_local, these aren't crud writes.
8690
buffer.push_str("WHEN NOT powersync_in_sync_operation()");
8791

88-
if write == WriteType::Update && !local_only_columns.as_ref().is_empty() {
92+
if write == WriteType::Update && synced_columns.is_some() {
8993
buffer.push_str(" AND\n(");
90-
// If we have local-only columns, we want to add additional WHEN clauses to ensure the
91-
// trigger runs for updates on synced columns.
94+
// If we have a filter for synced columns (instead of syncing all of them), we want to add
95+
// additional WHEN clauses to enesure the trigger runs for updates on those columns only.
9296
for (i, name) in as_schema_table.column_names().enumerate() {
9397
if i != 0 {
9498
buffer.push_str(" OR ");

crates/core/src/schema/table_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub struct RawTableSchema {
3838
#[serde(default)]
3939
pub table_name: Option<String>,
4040
#[serde(default)]
41-
pub local_only_columns: ColumnFilter,
41+
pub synced_columns: Option<ColumnFilter>,
4242
#[serde(flatten)]
4343
pub options: CommonTableOptions,
4444
}

dart/test/schema_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ END''',
288288
'CREATE TABLE users (id TEXT, synced_a TEXT, synced_b TEXT, local_a TEXT, local_b TEXT);',
289289
tableOptions: {
290290
'table_name': 'users',
291-
'local_only_columns': ['local_a', 'local_b'],
291+
'synced_columns': ['synced_a', 'synced_b'],
292292
},
293293
insert: '''
294294
CREATE TRIGGER "test_insert" AFTER INSERT ON "users" FOR EACH ROW WHEN NOT powersync_in_sync_operation() BEGIN

0 commit comments

Comments
 (0)