Skip to content

Commit 9d39c37

Browse files
committed
AI feedback
1 parent b045634 commit 9d39c37

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

powersync/src/db/schema.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ impl Schema {
3030
}
3131

3232
for table in &self.raw_tables {
33+
if !table_names.insert(table.name.as_ref()) {
34+
return Err(PowerSyncError::argument_error(format!(
35+
"Duplicate table name: {}",
36+
table.name,
37+
)));
38+
}
39+
3340
table.validate()?;
3441
}
3542

@@ -111,7 +118,7 @@ impl Table {
111118
for column in &self.columns {
112119
if column.name == "id" {
113120
return Err(PowerSyncError::argument_error(
114-
"id column is automatically added, cusotm id columns are not supported",
121+
"id column is automatically added, custom id columns are not supported",
115122
));
116123
}
117124

@@ -204,10 +211,12 @@ impl Serialize for TableOptions {
204211

205212
serializer.serialize_field("local_only", &self.local_only)?;
206213
serializer.serialize_field("insert_only", &self.insert_only)?;
214+
// Intentional field name, called ignore_empty_update in core extension
207215
serializer.serialize_field("ignore_empty_update", &self.ignore_empty_updates)?;
208216
serializer.serialize_field("include_metadata", &self.track_metadata)?;
209217

210218
if let Some(include_old) = &self.track_previous_values {
219+
// Intentional field name, "track previous" is called "include_old" in core extension.
211220
if let Some(filter) = &include_old.column_filter {
212221
serializer.serialize_field("include_old", &filter)?;
213222
} else {
@@ -495,7 +504,7 @@ impl TrackPreviousValues {
495504

496505
#[cfg(test)]
497506
mod test {
498-
use crate::schema::{Column, RawTable, RawTableSchema, Table, TrackPreviousValues};
507+
use crate::schema::{Column, RawTable, RawTableSchema, Schema, Table, TrackPreviousValues};
499508
use serde_json::json;
500509

501510
#[test]
@@ -596,4 +605,16 @@ mod test {
596605

597606
assert!(table.validate().is_err());
598607
}
608+
609+
#[test]
610+
fn invalid_duplicate_table() {
611+
let table = Table::create("users", vec![], |_| {});
612+
let raw_table = RawTable::with_schema("users", RawTableSchema::default());
613+
let schema = Schema {
614+
tables: vec![table],
615+
raw_tables: vec![raw_table],
616+
};
617+
618+
assert!(schema.validate().is_err());
619+
}
599620
}

0 commit comments

Comments
 (0)