-
Notifications
You must be signed in to change notification settings - Fork 620
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8484 from Turbo87/default-versions-table
Add `default_versions` database table
- Loading branch information
Showing
19 changed files
with
417 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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.