Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug that psqldef attempts to drop&add pk every time if two tables have same name and pk #190

Merged
merged 2 commits into from
Jan 23, 2022

Conversation

yuku
Copy link
Contributor

@yuku yuku commented Jan 23, 2022

Suppose there are two tables having:

  • same table name
  • same primary key column name
-- e.g.
create table user.accounts (id int primary key);
create table bank.accounts (id int primary key);

psqldef generates following DDL every time:

-- Apply --
ALTER TABLE "user"."accounts" DROP CONSTRAINT "accounts_pkey";
ALTER TABLE "user"."accounts" ADD primary key ("id");
ALTER TABLE "bank"."accounts" DROP CONSTRAINT "accounts_pkey";
ALTER TABLE "bank"."accounts" ADD primary key ("id");

This PR fixes this issue.

yuku added 2 commits January 23, 2022 22:10
…les have same name and pk

This commit fixes the failing test case added by 4f54e91
@yuku yuku changed the title Fix bug that psqldef attempts to drop&create pk every time if two tables have same name and pk Fix bug that psqldef attempts to drop&add pk every time if two tables have same name and pk Jan 23, 2022
@yuku yuku marked this pull request as ready for review January 23, 2022 13:47
@yuku
Copy link
Contributor Author

yuku commented Jan 23, 2022

@k0kubun Could you review this PR? 🙏

FYI: I bet there is almost same issue around getForeignDefs but I couldn't write regression tests, so I left it as is.

https://github.com/k0kubun/sqldef/blob/e0b45dd6f40f69d00c119c51c6514e24f8239a11/adapter/postgres/postgres.go#L415-L431

Copy link
Collaborator

@k0kubun k0kubun left a comment

Choose a reason for hiding this comment

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

Thanks!

@k0kubun k0kubun merged commit e7b7dae into sqldef:master Jan 23, 2022
@yuku yuku deleted the same-table-constraint-name branch January 23, 2022 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants