Electron100 / butane

An ORM for Rust with a focus on simplicity and on writing Rust, not SQL
Apache License 2.0
94 stars 13 forks source link

pg creates table with two primary key fields #204

Open jayvdb opened 6 months ago

jayvdb commented 6 months ago

In the same scenario as https://github.com/Electron100/butane/issues/201 , the pg backend creates an "up" script which keeps the old primary key which should have been dropped, and also adds sets the old field as a primary key, which fails with

called `Result::unwrap()` on an `Err` value: Postgres(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E42P16), message: "multiple primary keys for table \"mytable__butane_tmp\" are not allowed", detail: None, hint: None, position: Some(Original(195)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_utilcmd.c"), line: Some(2168), routine: Some("transformIndexConstraint") }) })

i.e.


CREATE TABLE MyTable__butane_tmp (
existing_field_becoming_pk_id JSONB NOT NULL PRIMARY KEY,
old_pk_id_which_should_have_been_removed JSONB NOT NULL PRIMARY KEY,
-- other fields
);