Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions src/seed/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,20 +319,34 @@ impl Database for PostgresDb {
.map(|c| format!("\"{}\"", sanitize_identifier(c)))
.collect();
let value_list: Vec<String> = values.iter().map(|v| escape_sql_value(v)).collect();
let returning_col = sanitize_identifier(auto_id_column.unwrap_or("id"));
let sql = format!(
"INSERT INTO \"{}\" ({}) VALUES ({}) RETURNING COALESCE(CAST(\"{}\" AS BIGINT), 0)",
sanitize_identifier(table),
col_list.join(", "),
value_list.join(", "),
returning_col
);
let row = self
.client
.query_one(&sql, &[])
.map_err(|e| format!("inserting row into '{}': {}", table, e))?;
let id: i64 = row.get(0);
Ok(Some(id))

if let Some(auto_col) = auto_id_column {
let returning_col = sanitize_identifier(auto_col);
let sql = format!(
"INSERT INTO \"{}\" ({}) VALUES ({}) RETURNING COALESCE(CAST(\"{}\" AS BIGINT), 0)",
sanitize_identifier(table),
col_list.join(", "),
value_list.join(", "),
returning_col
);
let row = self
.client
.query_one(&sql, &[])
.map_err(|e| format!("inserting row into '{}': {}", table, e))?;
let id: i64 = row.get(0);
Ok(Some(id))
} else {
let sql = format!(
"INSERT INTO \"{}\" ({}) VALUES ({})",
sanitize_identifier(table),
col_list.join(", "),
value_list.join(", "),
);
self.client
.execute(&sql, &[])
.map_err(|e| format!("inserting row into '{}': {}", table, e))?;
Ok(None)
}
Comment on lines +323 to +349
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new Postgres insert_row behavior (skipping RETURNING when auto_id_column is None) fixes the reported bug, but it isn’t covered by tests. There are existing Postgres seeding integration tests, but none exercise inserting into a table with a non-numeric primary key and no auto_id config; adding an integration test/fixture for that case would prevent regressions.

Copilot uses AI. Check for mistakes.
}

fn row_exists(
Expand Down