Skip to content

database: Add links column to versions table #5111

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
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions migrations/2022-08-18-152941_links-column/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE versions
DROP COLUMN links;
2 changes: 2 additions & 0 deletions migrations/2022-08-18-152941_links-column/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE versions
ADD COLUMN links VARCHAR NULL;
1 change: 1 addition & 0 deletions src/controllers/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ pub fn publish(req: &mut dyn RequestExt) -> EndpointResult {
file_length as i32,
user.id,
hex_cksum.clone(),
links.clone(),
)?
.save(&conn, &verified_email_address)?;

Expand Down
1 change: 1 addition & 0 deletions src/downloads_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ mod tests {
0,
self.user.id,
"0000000000000000000000000000000000000000000000000000000000000000".to_string(),
None,
)
.expect("failed to create version")
.save(conn, "ghost@example.com")
Expand Down
4 changes: 4 additions & 0 deletions src/models/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct Version {
pub crate_size: Option<i32>,
pub published_by: Option<i32>,
pub checksum: Option<String>,
pub links: Option<String>,
}

#[derive(Insertable, Debug)]
Expand All @@ -36,6 +37,7 @@ pub struct NewVersion {
crate_size: Option<i32>,
published_by: i32,
checksum: String,
links: Option<String>,
}

/// The highest version (semver order) and the most recently updated version.
Expand Down Expand Up @@ -133,6 +135,7 @@ impl NewVersion {
crate_size: i32,
published_by: i32,
checksum: String,
links: Option<String>,
) -> AppResult<Self> {
let features = serde_json::to_value(features)?;

Expand All @@ -144,6 +147,7 @@ impl NewVersion {
crate_size: Some(crate_size),
published_by,
checksum,
links,
};

new_version.validate_license(license_file)?;
Expand Down
6 changes: 6 additions & 0 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,12 @@ table! {
///
/// (Automatically generated by Diesel.)
checksum -> Nullable<Bpchar>,
/// The `links` column of the `versions` table.
///
/// Its SQL type is `Nullable<Varchar>`.
///
/// (Automatically generated by Diesel.)
links -> Nullable<Varchar>,
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/tests/builders/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct VersionBuilder<'a> {
size: i32,
yanked: bool,
checksum: String,
links: Option<String>,
}

impl<'a> VersionBuilder<'a> {
Expand All @@ -43,6 +44,7 @@ impl<'a> VersionBuilder<'a> {
size: 0,
yanked: false,
checksum: String::new(),
links: None,
}
}

Expand Down Expand Up @@ -94,6 +96,7 @@ impl<'a> VersionBuilder<'a> {
self.size,
published_by,
self.checksum,
self.links,
)?
.save(connection, "someone@example.com")?;

Expand Down
1 change: 1 addition & 0 deletions src/worker/dump_db/dump-db.toml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ license = "public"
crate_size = "public"
published_by = "public"
checksum = "public"
links = "public"

[versions_published_by.columns]
version_id = "private"
Expand Down
1 change: 1 addition & 0 deletions src/worker/update_downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ mod test {
0,
user_id,
"0000000000000000000000000000000000000000000000000000000000000000".to_string(),
None,
)
.unwrap();
let version = version.save(conn, "someone@example.com").unwrap();
Expand Down