Skip to content

Commit b42617a

Browse files
authored
database: Add links column to versions table (#5111)
1 parent 78a3f7e commit b42617a

File tree

9 files changed

+21
-0
lines changed

9 files changed

+21
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE versions
2+
DROP COLUMN links;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE versions
2+
ADD COLUMN links VARCHAR NULL;

src/controllers/krate/publish.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ pub fn publish(req: &mut dyn RequestExt) -> EndpointResult {
171171
file_length as i32,
172172
user.id,
173173
hex_cksum.clone(),
174+
links.clone(),
174175
)?
175176
.save(&conn, &verified_email_address)?;
176177

src/downloads_counter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ mod tests {
458458
0,
459459
self.user.id,
460460
"0000000000000000000000000000000000000000000000000000000000000000".to_string(),
461+
None,
461462
)
462463
.expect("failed to create version")
463464
.save(conn, "ghost@example.com")

src/models/version.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub struct Version {
2424
pub crate_size: Option<i32>,
2525
pub published_by: Option<i32>,
2626
pub checksum: Option<String>,
27+
pub links: Option<String>,
2728
}
2829

2930
#[derive(Insertable, Debug)]
@@ -36,6 +37,7 @@ pub struct NewVersion {
3637
crate_size: Option<i32>,
3738
published_by: i32,
3839
checksum: String,
40+
links: Option<String>,
3941
}
4042

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

@@ -144,6 +147,7 @@ impl NewVersion {
144147
crate_size: Some(crate_size),
145148
published_by,
146149
checksum,
150+
links,
147151
};
148152

149153
new_version.validate_license(license_file)?;

src/schema.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,12 @@ table! {
994994
///
995995
/// (Automatically generated by Diesel.)
996996
checksum -> Nullable<Bpchar>,
997+
/// The `links` column of the `versions` table.
998+
///
999+
/// Its SQL type is `Nullable<Varchar>`.
1000+
///
1001+
/// (Automatically generated by Diesel.)
1002+
links -> Nullable<Varchar>,
9971003
}
9981004
}
9991005

src/tests/builders/version.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub struct VersionBuilder<'a> {
1919
size: i32,
2020
yanked: bool,
2121
checksum: String,
22+
links: Option<String>,
2223
}
2324

2425
impl<'a> VersionBuilder<'a> {
@@ -43,6 +44,7 @@ impl<'a> VersionBuilder<'a> {
4344
size: 0,
4445
yanked: false,
4546
checksum: String::new(),
47+
links: None,
4648
}
4749
}
4850

@@ -94,6 +96,7 @@ impl<'a> VersionBuilder<'a> {
9496
self.size,
9597
published_by,
9698
self.checksum,
99+
self.links,
97100
)?
98101
.save(connection, "someone@example.com")?;
99102

src/worker/dump_db/dump-db.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ license = "public"
214214
crate_size = "public"
215215
published_by = "public"
216216
checksum = "public"
217+
links = "public"
217218

218219
[versions_published_by.columns]
219220
version_id = "private"

src/worker/update_downloads.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ mod test {
109109
0,
110110
user_id,
111111
"0000000000000000000000000000000000000000000000000000000000000000".to_string(),
112+
None,
112113
)
113114
.unwrap();
114115
let version = version.save(conn, "someone@example.com").unwrap();

0 commit comments

Comments
 (0)