-
Notifications
You must be signed in to change notification settings - Fork 212
Fix owner_rels.cid
foreign key reference
#926
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
Changes from all commits
e7407bf
9944854
0da6269
43940d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -364,6 +364,22 @@ pub fn migrate(version: Option<Version>, conn: &Connection) -> CratesfyiResult<( | |||||
"DROP TABLE compression_rels; | ||||||
ALTER TABLE files DROP COLUMN compression;" | ||||||
), | ||||||
migration!( | ||||||
context, | ||||||
// version | ||||||
15, | ||||||
// description | ||||||
"Fix owner_rels.cid foreign key reference", | ||||||
// upgrade query | ||||||
" | ||||||
ALTER TABLE owner_rels DROP CONSTRAINT owner_rels_cid_fkey; | ||||||
ALTER TABLE owner_rels ADD FOREIGN KEY (cid) REFERENCES crates(id); | ||||||
Comment on lines
+375
to
+376
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if I understand this correctly:
However I don't think the last point is entirely true: When I wrote Line 65 in 7ab8306
Line 102 in 7ab8306
cc @pietroalbini: do not delete any more crates until this is fixed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, that all sounds correct, I've fixed it in the latest commit. I don't see any easy way to really test the behaviour. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fortunately this part of the code is (since #917) self-correcting so the worst that can happen is that the owner is missing until the next publish. Thanks for working on this :) |
||||||
", | ||||||
// downgrade query | ||||||
" | ||||||
-- Nope, this is a pure database fix, no going back. | ||||||
" | ||||||
), | ||||||
]; | ||||||
|
||||||
for migration in migrations { | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,6 +239,29 @@ impl TestDatabase { | |
))?; | ||
crate::db::migrate(None, &conn)?; | ||
|
||
// Move all sequence start positions 10000 apart to avoid overlapping primary keys | ||
let query: String = conn | ||
.query( | ||
" | ||
SELECT relname | ||
FROM pg_class | ||
INNER JOIN pg_namespace | ||
ON pg_class.relnamespace = pg_namespace.oid | ||
WHERE pg_class.relkind = 'S' | ||
AND pg_namespace.nspname = $1 | ||
Comment on lines
+246
to
+251
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dark magics 😨 |
||
", | ||
&[&schema], | ||
)? | ||
.into_iter() | ||
.map(|row| row.get(0)) | ||
.enumerate() | ||
.map(|(i, sequence): (_, String)| { | ||
let offset = (i + 1) * 10000; | ||
format!(r#"ALTER SEQUENCE "{}" RESTART WITH {};"#, sequence, offset) | ||
}) | ||
.collect(); | ||
conn.batch_execute(&query)?; | ||
|
||
Ok(TestDatabase { | ||
pool: Pool::new_with_schema(config, &schema)?, | ||
schema, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to say you only do this for deleting a crate, not a version, then I realized that's the right behavior and it was just buggy before 😅