-
Notifications
You must be signed in to change notification settings - Fork 653
Add default_versions
database table
#8484
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
67cd7db
sql: Add `SemverVersion` wrapper
Turbo87 996bf77
database: Add `default_versions` table
Turbo87 21edf35
Implement `update_default_version()` fn
Turbo87 dd6fb89
admin: Implement `update-default-versions` command
Turbo87 0325594
admin/delete_version: Run `update_default_version()` after versions a…
Turbo87 ebc562f
worker/jobs: Implement `UpdateDefaultVersion` background job
Turbo87 3f09870
controllers/krate/publish: Update `default_versions` table
Turbo87 d39543a
controllers/version/yank: Enqueue `UpdateDefaultVersion` job
Turbo87 fef072e
admin/yank_version: Enqueue `UpdateDefaultVersion` job
Turbo87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
drop table default_versions; |
24 changes: 24 additions & 0 deletions
24
migrations/2024-04-17-135931_default-versions-table/up.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
create table default_versions | ||
( | ||
crate_id integer not null | ||
constraint default_versions_pk | ||
primary key | ||
constraint default_versions_crates_id_fk | ||
references crates | ||
on delete cascade, | ||
version_id integer not null | ||
constraint default_versions_versions_id_fk | ||
references versions | ||
on delete no action deferrable initially deferred | ||
); | ||
|
||
create unique index default_versions_version_id_uindex | ||
on default_versions (version_id); | ||
|
||
comment on table default_versions is 'A mapping from crates to the versions that the frontend will display by default.'; | ||
comment on column default_versions.crate_id is 'Reference to the crate in the `crates` table.'; | ||
comment on column default_versions.version_id is 'Reference to the version in the `versions` table.'; | ||
comment on constraint default_versions_crates_id_fk on default_versions is | ||
'This is a `cascade` delete because we want to delete the row when the crate is deleted.'; | ||
comment on constraint default_versions_versions_id_fk on default_versions is | ||
'This is a `no action` delete because we want to fail the version deletion unless the default version is updated in the same transaction.'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use crate::models::update_default_version; | ||
use crate::{db, schema::crates}; | ||
use anyhow::Context; | ||
use diesel::prelude::*; | ||
use indicatif::{ProgressBar, ProgressIterator, ProgressStyle}; | ||
|
||
#[derive(clap::Parser, Debug)] | ||
#[clap( | ||
name = "update-default-versions", | ||
about = "Iterates over every crate ever uploaded and updates the `default_versions` table." | ||
)] | ||
pub struct Opts; | ||
|
||
pub fn run(_opts: Opts) -> anyhow::Result<()> { | ||
let mut conn = db::oneoff_connection().context("Failed to connect to the database")?; | ||
|
||
let crate_ids: Vec<i32> = crates::table | ||
.select(crates::id) | ||
.load(&mut conn) | ||
.context("Failed to load crates")?; | ||
|
||
let pb = ProgressBar::new(crate_ids.len() as u64); | ||
pb.set_style(ProgressStyle::with_template( | ||
"{bar:60} ({pos}/{len}, ETA {eta})", | ||
)?); | ||
|
||
for crate_id in crate_ids.into_iter().progress_with(pb.clone()) { | ||
if let Err(error) = update_default_version(crate_id, &mut conn) { | ||
pb.suspend(|| warn!(%crate_id, %error, "Failed to update the default version")); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.