Skip to content

Commit 66c60dc

Browse files
committed
Auto merge of #1815 - rye:remove-crates-license-column, r=sgrif
Remove `license` column on `crates` table Seemingly the last step in the checklist on #736, this PR removes the `license` column on the `crates` table, and all references thereto. (In fact, I think #736 can be closed once this PR is merged.) As of #803, the front-end no longer really used this field, and the front-end was also changed to render the license of the _current_ version, instead of the value coming from this now-obsolete `license` column on the crate. Thus, this column likely contains stale data and, to my knowledge, isn't changed at all when a new version is uploaded. I wasn't sure what requirements are enforced for backwards-compatibility, or whether my changes here would actually affect behavior of e.g. if there are old versions of `cargo` that will upload with these values. I am happy for these changes to be scrutinized until this is verified to be safe.
2 parents 6514cdb + 37bd286 commit 66c60dc

File tree

8 files changed

+11
-45
lines changed

8 files changed

+11
-45
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- This file should undo anything in `up.sql`
2+
ALTER TABLE crates ADD COLUMN license VARCHAR;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- ALERT! DESTRUCTIVE MIGRATION
2+
-- DO NOT DEPLOY UNTIL PREVIOUS COMMIT IS DEPLOYED
3+
ALTER TABLE crates DROP COLUMN license;

src/controllers/krate/publish.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,12 @@ pub fn publish(req: &mut dyn Request) -> CargoResult<Response> {
7979
documentation: new_crate.documentation.as_ref().map(|s| &**s),
8080
readme: new_crate.readme.as_ref().map(|s| &**s),
8181
repository: repo.as_ref().map(String::as_str),
82-
license: new_crate.license.as_ref().map(|s| &**s),
8382
max_upload_size: None,
8483
};
8584

8685
let license_file = new_crate.license_file.as_ref().map(|s| &**s);
87-
let krate = persist.create_or_update(
88-
&conn,
89-
license_file,
90-
user.id,
91-
Some(&app.config.publish_rate_limit),
92-
)?;
86+
let krate =
87+
persist.create_or_update(&conn, user.id, Some(&app.config.publish_rate_limit))?;
9388

9489
let owners = krate.owners(&conn)?;
9590
if user.rights(req.app(), &owners)? < Rights::Publish {

src/models/krate.rs

+2-29
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ pub struct Crate {
4343
pub description: Option<String>,
4444
pub homepage: Option<String>,
4545
pub documentation: Option<String>,
46-
pub license: Option<String>,
4746
pub repository: Option<String>,
4847
pub max_upload_size: Option<i32>,
4948
}
@@ -59,7 +58,6 @@ type AllColumns = (
5958
crates::description,
6059
crates::homepage,
6160
crates::documentation,
62-
crates::license,
6361
crates::repository,
6462
crates::max_upload_size,
6563
);
@@ -73,7 +71,6 @@ pub const ALL_COLUMNS: AllColumns = (
7371
crates::description,
7472
crates::homepage,
7573
crates::documentation,
76-
crates::license,
7774
crates::repository,
7875
crates::max_upload_size,
7976
);
@@ -98,20 +95,18 @@ pub struct NewCrate<'a> {
9895
pub readme: Option<&'a str>,
9996
pub repository: Option<&'a str>,
10097
pub max_upload_size: Option<i32>,
101-
pub license: Option<&'a str>,
10298
}
10399

104100
impl<'a> NewCrate<'a> {
105101
pub fn create_or_update(
106102
mut self,
107103
conn: &PgConnection,
108-
license_file: Option<&'a str>,
109104
uploader: i32,
110105
rate_limit: Option<&PublishRateLimit>,
111106
) -> CargoResult<Crate> {
112107
use diesel::update;
113108

114-
self.validate(license_file)?;
109+
self.validate()?;
115110
self.ensure_name_not_reserved(conn)?;
116111

117112
conn.transaction(|| {
@@ -133,7 +128,7 @@ impl<'a> NewCrate<'a> {
133128
})
134129
}
135130

136-
fn validate(&mut self, license_file: Option<&'a str>) -> CargoResult<()> {
131+
fn validate(&mut self) -> CargoResult<()> {
137132
fn validate_url(url: Option<&str>, field: &str) -> CargoResult<()> {
138133
let url = match url {
139134
Some(s) => s,
@@ -164,28 +159,6 @@ impl<'a> NewCrate<'a> {
164159
validate_url(self.homepage, "homepage")?;
165160
validate_url(self.documentation, "documentation")?;
166161
validate_url(self.repository, "repository")?;
167-
self.validate_license(license_file)?;
168-
Ok(())
169-
}
170-
171-
fn validate_license(&mut self, license_file: Option<&str>) -> CargoResult<()> {
172-
if let Some(license) = self.license {
173-
for part in license.split('/') {
174-
license_exprs::validate_license_expr(part).map_err(|e| {
175-
human(&format_args!(
176-
"{}; see http://opensource.org/licenses \
177-
for options, and http://spdx.org/licenses/ \
178-
for their identifiers",
179-
e
180-
))
181-
})?;
182-
}
183-
} else if license_file.is_some() {
184-
// If no license is given, but a license file is given, flag this
185-
// crate as having a nonstandard license. Note that we don't
186-
// actually do anything else with license_file currently.
187-
self.license = Some("non-standard");
188-
}
189162
Ok(())
190163
}
191164

src/models/token.rs

-1
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,4 @@ mod tests {
9696
.find(r#""last_used_at":"2017-01-06T14:23:12+00:00""#)
9797
.is_some());
9898
}
99-
10099
}

src/schema.rs

-6
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,6 @@ table! {
332332
///
333333
/// (Automatically generated by Diesel.)
334334
textsearchable_index_col -> Tsvector,
335-
/// The `license` column of the `crates` table.
336-
///
337-
/// Its SQL type is `Nullable<Varchar>`.
338-
///
339-
/// (Automatically generated by Diesel.)
340-
license -> Nullable<Varchar>,
341335
/// The `repository` column of the `crates` table.
342336
///
343337
/// Its SQL type is `Nullable<Varchar>`.

src/tasks/update_downloads.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ mod test {
103103
name: "foo",
104104
..Default::default()
105105
}
106-
.create_or_update(conn, None, user_id, None)
106+
.create_or_update(conn, user_id, None)
107107
.unwrap();
108108
let version = NewVersion::new(
109109
krate.id,

src/tests/builders.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl<'a> CrateBuilder<'a> {
234234

235235
let mut krate = self
236236
.krate
237-
.create_or_update(connection, None, self.owner_id, None)?;
237+
.create_or_update(connection, self.owner_id, None)?;
238238

239239
// Since we are using `NewCrate`, we can't set all the
240240
// crate properties in a single DB call.

0 commit comments

Comments
 (0)