Skip to content

Commit f6702c6

Browse files
committed
Remove crate_downloads
No part of our code base relies on this table any longer, so we can just remove it.
1 parent daf0751 commit f6702c6

File tree

4 files changed

+19
-33
lines changed

4 files changed

+19
-33
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CREATE TABLE crate_downloads (
2+
crate_id INTEGER NOT NULL REFERENCES crates (id),
3+
downloads INTEGER NOT NULL,
4+
date DATE NOT NULL,
5+
PRIMARY KEY (crate_id, date)
6+
);
7+
CREATE INDEX "index_crate_downloads_crate_id" ON crate_downloads (crate_id);
8+
CREATE INDEX "index_crate_downloads_date" ON crate_downloads (date);
9+
10+
INSERT INTO crate_downloads (crate_id, downloads, date)
11+
SELECT crate_id, sum(version_downloads.downloads), date
12+
FROM version_downloads
13+
INNER JOIN versions
14+
ON version_downloads.version_id = versions.id
15+
GROUP BY (crate_id, date);
Lines changed: 3 additions & 0 deletions
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+
DROP TABLE crate_downloads;

src/schema.patch

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ index df884e4..18e08cd 100644
5555

5656
/// Representation of the `reserved_crate_names` table.
5757
///
58-
@@ -881,22 +901,24 @@ table! {
58+
@@ -881,21 +901,23 @@ table! {
5959
}
6060

6161
joinable!(api_tokens -> users (user_id));
62-
joinable!(crate_downloads -> crates (crate_id));
6362
joinable!(crate_owner_invitations -> crates (crate_id));
6463
joinable!(crate_owners -> crates (crate_id));
6564
-joinable!(crate_owners -> users (created_by));

src/schema.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -176,35 +176,6 @@ table! {
176176
}
177177
}
178178

179-
table! {
180-
use diesel::sql_types::*;
181-
use diesel_full_text_search::{TsVector as Tsvector};
182-
183-
/// Representation of the `crate_downloads` table.
184-
///
185-
/// (Automatically generated by Diesel.)
186-
crate_downloads (crate_id, date) {
187-
/// The `crate_id` column of the `crate_downloads` table.
188-
///
189-
/// Its SQL type is `Int4`.
190-
///
191-
/// (Automatically generated by Diesel.)
192-
crate_id -> Int4,
193-
/// The `downloads` column of the `crate_downloads` table.
194-
///
195-
/// Its SQL type is `Int4`.
196-
///
197-
/// (Automatically generated by Diesel.)
198-
downloads -> Int4,
199-
/// The `date` column of the `crate_downloads` table.
200-
///
201-
/// Its SQL type is `Date`.
202-
///
203-
/// (Automatically generated by Diesel.)
204-
date -> Date,
205-
}
206-
}
207-
208179
table! {
209180
use diesel::sql_types::*;
210181
use diesel_full_text_search::{TsVector as Tsvector};
@@ -956,7 +927,6 @@ table! {
956927
}
957928

958929
joinable!(api_tokens -> users (user_id));
959-
joinable!(crate_downloads -> crates (crate_id));
960930
joinable!(crate_owner_invitations -> crates (crate_id));
961931
joinable!(crate_owners -> crates (crate_id));
962932
joinable!(crate_owners -> teams (owner_id));
@@ -984,7 +954,6 @@ allow_tables_to_appear_in_same_query!(
984954
background_jobs,
985955
badges,
986956
categories,
987-
crate_downloads,
988957
crate_owner_invitations,
989958
crate_owners,
990959
crates,

0 commit comments

Comments
 (0)