Skip to content

feat(coderd/database): generate foreign key constraints and add database.IsForeignKeyViolation #9657

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

Merged
merged 2 commits into from
Sep 13, 2023

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Sep 13, 2023

I saw that we were generating this for unique constraints and thought it might be useful to add it for foreign keys as well (to be used in a follow-up PR)

@johnstcn johnstcn self-assigned this Sep 13, 2023
@johnstcn johnstcn changed the title feat(coderd/database): generate foreign key constraints, add database.IsForeignKeyViolation feat(coderd/database): generate foreign key constraints and add database.IsForeignKeyViolation Sep 13, 2023
@johnstcn johnstcn marked this pull request as ready for review September 13, 2023 10:20
Copy link
Member Author

Choose a reason for hiding this comment

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

note: I haven't performed any DRY refactoring on this piece here; I figure de-duplication is premature.

Copy link
Member

Choose a reason for hiding this comment

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

💯 agreed.

Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

(to be used in a follow-up PR)

👍

name := ""
switch {
case strings.Contains(query, "ALTER TABLE") && strings.Contains(query, "ADD CONSTRAINT"):
name = strings.Split(query, " ")[6]
Copy link
Contributor

Choose a reason for hiding this comment

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

parsing is pretty flimsy, but I guess the rest of the file is no better...

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah... it works for the moment.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's worth improving, SQL is pretty stable 😄.

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Thanks for adding this! ❤️

@johnstcn johnstcn merged commit 2ac5329 into main Sep 13, 2023
@johnstcn johnstcn deleted the cj/dbgen-fk-constraints branch September 13, 2023 12:28
@github-actions github-actions bot locked and limited conversation to collaborators Sep 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants