Skip to content

Add missing foreign key constraint for columns badges.crate_id. #1840

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 1 commit into from
Sep 18, 2019

Conversation

smarnach
Copy link
Contributor

Since we may already have entries in the badges table referring to crates that don't exist, we
need to delete these entries before creating the foreign key constraint. This is a destructive
operation in the sense that it cannot be reverted, but it should only delete rows that should have
been deleted together with the crates they belong to.

We have a test to verify that all columns called crate_id are actually foreign keys referring to
crates.id. However, the query for the relevant columns contains the filter contype = 'f',
effectively limiting the result to columns that already have foreign key constraints. This change
fixes the query to also allow contype IS NULL.

In addition, I modified the query to only verify tables in the schema public. This is useful for
an integration test for the database dumps in #1800.

Since we may already have entries in the `badges` table referring to crates that don't exist, we
need to delete these entries before creating the foreign key constraint. This is a destructive
operation in the sense that it cannot be reverted, but it should only delete rows that should have
been deleted together with the crates they belong to.

We have a test to verify that all columns called `crate_id` are actually foreign keys referring to
`crates.id`. However, the query for the relevant columns contains the filter `contype = 'f'`,
effectively limiting the result to columns that already have foreign key constraints. This change
fixes the query to also allow `contype IS NULL`.

In addition, I modified the query to only verify tables in the schema `public`. This is useful for
an integration test for the database dumps in rust-lang#1800.
@rust-highfive
Copy link

r? @carols10cents

(rust_highfive has picked a reviewer for you, use r? to override)

@sgrif
Copy link
Contributor

sgrif commented Sep 18, 2019

I've confirmed that all rows in production to be deleted are in fact rows that should have already been deleted.

@bors: r+

@bors
Copy link
Contributor

bors commented Sep 18, 2019

📌 Commit 7ef85f5 has been approved by sgrif

@bors
Copy link
Contributor

bors commented Sep 18, 2019

⌛ Testing commit 7ef85f5 with merge 12c64bc...

bors added a commit that referenced this pull request Sep 18, 2019
Add missing foreign key constraint for columns badges.crate_id.

Since we may already have entries in the `badges` table referring to crates that don't exist, we
need to delete these entries before creating the foreign key constraint. This is a destructive
operation in the sense that it cannot be reverted, but it should only delete rows that should have
been deleted together with the crates they belong to.

We have a test to verify that all columns called `crate_id` are actually foreign keys referring to
`crates.id`. However, the query for the relevant columns contains the filter `contype = 'f'`,
effectively limiting the result to columns that already have foreign key constraints. This change
fixes the query to also allow `contype IS NULL`.

In addition, I modified the query to only verify tables in the schema `public`. This is useful for
an integration test for the database dumps in #1800.
@bors
Copy link
Contributor

bors commented Sep 18, 2019

☀️ Test successful - checks-travis
Approved by: sgrif
Pushing 12c64bc to master...

@bors bors merged commit 7ef85f5 into rust-lang:master Sep 18, 2019
@bors bors mentioned this pull request Sep 18, 2019
9 tasks
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.

5 participants