From 62d3934ae51715d63517972336305092e623612f Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 19 Feb 2024 12:53:09 +0100 Subject: [PATCH] database: Drop `badges` table We haven't returned the data from the API for two years and haven't shown the badges on the frontend for four years, so it's time to get rid of the unused data in the database. --- .../down.sql | 10 +++++++ .../up.sql | 1 + src/schema.patch | 28 ++++++++----------- src/schema.rs | 28 ------------------- src/worker/jobs/dump_db/dump-db.toml | 7 ----- 5 files changed, 23 insertions(+), 51 deletions(-) create mode 100644 migrations/2024-02-19-113226_delete-badges-table/down.sql create mode 100644 migrations/2024-02-19-113226_delete-badges-table/up.sql diff --git a/migrations/2024-02-19-113226_delete-badges-table/down.sql b/migrations/2024-02-19-113226_delete-badges-table/down.sql new file mode 100644 index 00000000000..294367ee631 --- /dev/null +++ b/migrations/2024-02-19-113226_delete-badges-table/down.sql @@ -0,0 +1,10 @@ +create table if not exists badges +( + crate_id integer not null + constraint fk_badges_crate_id + references crates + on delete cascade, + badge_type varchar not null, + attributes jsonb not null, + primary key (crate_id, badge_type) +); diff --git a/migrations/2024-02-19-113226_delete-badges-table/up.sql b/migrations/2024-02-19-113226_delete-badges-table/up.sql new file mode 100644 index 00000000000..80a4c936194 --- /dev/null +++ b/migrations/2024-02-19-113226_delete-badges-table/up.sql @@ -0,0 +1 @@ +drop table badges; diff --git a/src/schema.patch b/src/schema.patch index 9fd01243a02..41d845bd20a 100644 --- a/src/schema.patch +++ b/src/schema.patch @@ -1,8 +1,4 @@ -diff --git a/src/schema.rs b/src/schema.rs -index bb2658942..1bc6801ea 100644 ---- a/src/schema.rs -+++ b/src/schema.rs -@@ -14,9 +14,7 @@ pub mod sql_types { +@@ -21,9 +21,7 @@ /// The `pg_catalog.tsvector` SQL type /// /// (Automatically generated by Diesel.) @@ -13,7 +9,7 @@ index bb2658942..1bc6801ea 100644 } diesel::table! { -@@ -67,9 +65,9 @@ diesel::table! { +@@ -74,9 +72,9 @@ /// (Automatically generated by Diesel.) revoked -> Bool, /// NULL or an array of crate scope patterns (see RFC #2947) @@ -25,7 +21,7 @@ index bb2658942..1bc6801ea 100644 /// The `expired_at` column of the `api_tokens` table. /// /// Its SQL type is `Nullable`. -@@ -193,12 +191,6 @@ diesel::table! { +@@ -180,12 +178,6 @@ /// /// (Automatically generated by Diesel.) created_at -> Timestamp, @@ -38,7 +34,7 @@ index bb2658942..1bc6801ea 100644 } } -@@ -471,7 +463,7 @@ diesel::table! { +@@ -456,7 +448,7 @@ /// Its SQL type is `Array>`. /// /// (Automatically generated by Diesel.) @@ -47,11 +43,10 @@ index bb2658942..1bc6801ea 100644 /// The `target` column of the `dependencies` table. /// /// Its SQL type is `Nullable`. -@@ -675,6 +667,24 @@ diesel::table! { - } +@@ -683,6 +675,24 @@ } -+diesel::table! { + diesel::table! { + /// Representation of the `recent_crate_downloads` view. + /// + /// This data represents the downloads in the last 90 days. @@ -69,11 +64,12 @@ index bb2658942..1bc6801ea 100644 + } +} + - diesel::table! { ++diesel::table! { /// Representation of the `reserved_crate_names` table. /// -@@ -988,7 +998,8 @@ diesel::joinable!(api_tokens -> users (user_id)); - diesel::joinable!(badges -> crates (crate_id)); + /// (Automatically generated by Diesel.) +@@ -997,7 +1007,8 @@ + diesel::joinable!(api_tokens -> users (user_id)); diesel::joinable!(crate_owner_invitations -> crates (crate_id)); diesel::joinable!(crate_owners -> crates (crate_id)); -diesel::joinable!(crate_owners -> users (created_by)); @@ -82,7 +78,7 @@ index bb2658942..1bc6801ea 100644 diesel::joinable!(crates_categories -> categories (category_id)); diesel::joinable!(crates_categories -> crates (crate_id)); diesel::joinable!(crates_keywords -> crates (crate_id)); -@@ -1001,6 +1012,7 @@ diesel::joinable!(follows -> users (user_id)); +@@ -1010,6 +1021,7 @@ diesel::joinable!(publish_limit_buckets -> users (user_id)); diesel::joinable!(publish_rate_overrides -> users (user_id)); diesel::joinable!(readme_renderings -> versions (version_id)); @@ -90,7 +86,7 @@ index bb2658942..1bc6801ea 100644 diesel::joinable!(version_downloads -> versions (version_id)); diesel::joinable!(version_owner_actions -> api_tokens (api_token_id)); diesel::joinable!(version_owner_actions -> users (user_id)); -@@ -1027,6 +1039,7 @@ diesel::allow_tables_to_appear_in_same_query!( +@@ -1036,6 +1048,7 @@ publish_limit_buckets, publish_rate_overrides, readme_renderings, diff --git a/src/schema.rs b/src/schema.rs index fb4d28206dc..ef12c684f2e 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -134,32 +134,6 @@ diesel::table! { } } -diesel::table! { - /// Representation of the `badges` table. - /// - /// (Automatically generated by Diesel.) - badges (crate_id, badge_type) { - /// The `crate_id` column of the `badges` table. - /// - /// Its SQL type is `Int4`. - /// - /// (Automatically generated by Diesel.) - crate_id -> Int4, - /// The `badge_type` column of the `badges` table. - /// - /// Its SQL type is `Varchar`. - /// - /// (Automatically generated by Diesel.) - badge_type -> Varchar, - /// The `attributes` column of the `badges` table. - /// - /// Its SQL type is `Jsonb`. - /// - /// (Automatically generated by Diesel.) - attributes -> Jsonb, - } -} - diesel::table! { use diesel::sql_types::*; use super::sql_types::Ltree; @@ -1031,7 +1005,6 @@ diesel::table! { } diesel::joinable!(api_tokens -> users (user_id)); -diesel::joinable!(badges -> crates (crate_id)); diesel::joinable!(crate_owner_invitations -> crates (crate_id)); diesel::joinable!(crate_owners -> crates (crate_id)); diesel::joinable!(crate_owners -> teams (owner_id)); @@ -1060,7 +1033,6 @@ diesel::joinable!(versions_published_by -> versions (version_id)); diesel::allow_tables_to_appear_in_same_query!( api_tokens, background_jobs, - badges, categories, crate_owner_invitations, crate_owners, diff --git a/src/worker/jobs/dump_db/dump-db.toml b/src/worker/jobs/dump_db/dump-db.toml index 88b3fc770d4..f8b29e08265 100644 --- a/src/worker/jobs/dump_db/dump-db.toml +++ b/src/worker/jobs/dump_db/dump-db.toml @@ -39,13 +39,6 @@ last_retry = "private" created_at = "private" priority = "private" -[badges] -dependencies = ["crates"] -[badges.columns] -crate_id = "public" -badge_type = "public" -attributes = "public" - [categories.columns] id = "public" category = "public"