Skip to content

Commit

Permalink
Fix incorrect behavior when adding an autoincrement column to a Postg…
Browse files Browse the repository at this point in the history
…res table.
  • Loading branch information
opusbopus committed Sep 7, 2023
1 parent 36c03c3 commit d30df59
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/backend/postgres/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ impl TableBuilder for PostgresQueryBuilder {
let f = |column_def: &ColumnDef, sql: &mut dyn SqlWriter| {
if let Some(column_type) = &column_def.types {
write!(sql, " ").unwrap();
self.prepare_column_type(column_type, sql);
if column_def.spec.iter().any(|v| matches!(v, ColumnSpec::AutoIncrement)) {
self.prepare_column_auto_increment(column_type, sql);
} else {
self.prepare_column_type(column_type, sql);
}
}
};
self.prepare_column_def_common(column, sql, f);
Expand Down
4 changes: 2 additions & 2 deletions tests/postgres/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ fn alter_9() {

#[test]
fn alter_10() {
// https://dbfiddle.uk/PQksflGf
// https://dbfiddle.uk/BeiZPvBe
assert_eq!(
Table::alter()
.table(Glyph::Table)
Expand All @@ -534,7 +534,7 @@ fn alter_10() {
.to_string(PostgresQueryBuilder),
[
r#"ALTER TABLE "glyph""#,
r#"ADD COLUMN "aspect" integer NOT NULL UNIQUE PRIMARY KEY"#,
r#"ADD COLUMN "aspect" serial NOT NULL UNIQUE PRIMARY KEY"#,
]
.join(" ")
);
Expand Down

0 comments on commit d30df59

Please sign in to comment.