From 4f5e51beb5839d50e72b1362ac9ed2e16be1c9a9 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 16 Dec 2020 22:42:25 -0500 Subject: [PATCH] Removing fast tables and old views. --- docker/docker_db_backup.sh | 5 +- lemmy_db/Cargo.toml | 2 +- lemmy_db/src/schema.rs | 141 ------------------ .../down.sql | 1 + .../up.sql | 7 + .../down.sql | 4 + .../up.sql | 41 +++++ 7 files changed, 58 insertions(+), 143 deletions(-) create mode 100644 migrations/2020-12-17-030456_create_alias_views/down.sql create mode 100644 migrations/2020-12-17-030456_create_alias_views/up.sql create mode 100644 migrations/2020-12-17-031053_remove_fast_tables_and_views/down.sql create mode 100644 migrations/2020-12-17-031053_remove_fast_tables_and_views/up.sql diff --git a/docker/docker_db_backup.sh b/docker/docker_db_backup.sh index d42826e06..e9473a290 100755 --- a/docker/docker_db_backup.sh +++ b/docker/docker_db_backup.sh @@ -1 +1,4 @@ -docker exec -it dev_lemmy_db_1 pg_dumpall -c -U rrr > dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql +#!/bin/bash +pushd dev +docker-compose exec postgres pg_dumpall -c -U lemmy > dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql +popd diff --git a/lemmy_db/Cargo.toml b/lemmy_db/Cargo.toml index 11b27fcd7..d7c0fe3b0 100644 --- a/lemmy_db/Cargo.toml +++ b/lemmy_db/Cargo.toml @@ -9,7 +9,7 @@ path = "src/lib.rs" [dependencies] lemmy_utils = { path = "../lemmy_utils" } -diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","64-column-tables","serde_json"] } +diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] } chrono = { version = "0.4.19", features = ["serde"] } serde = { version = "1.0.118", features = ["derive"] } serde_json = { version = "1.0.60", features = ["preserve_order"] } diff --git a/lemmy_db/src/schema.rs b/lemmy_db/src/schema.rs index 75883df57..33e2389fd 100644 --- a/lemmy_db/src/schema.rs +++ b/lemmy_db/src/schema.rs @@ -44,42 +44,6 @@ table! { } } -table! { - comment_aggregates_fast (id) { - id -> Int4, - creator_id -> Nullable, - post_id -> Nullable, - parent_id -> Nullable, - content -> Nullable, - removed -> Nullable, - read -> Nullable, - published -> Nullable, - updated -> Nullable, - deleted -> Nullable, - ap_id -> Nullable, - local -> Nullable, - post_name -> Nullable, - community_id -> Nullable, - community_actor_id -> Nullable, - community_local -> Nullable, - community_name -> Nullable, - community_icon -> Nullable, - banned -> Nullable, - banned_from_community -> Nullable, - creator_actor_id -> Nullable, - creator_local -> Nullable, - creator_name -> Nullable, - creator_preferred_username -> Nullable, - creator_published -> Nullable, - creator_avatar -> Nullable, - score -> Nullable, - upvotes -> Nullable, - downvotes -> Nullable, - hot_rank -> Nullable, - hot_rank_active -> Nullable, - } -} - table! { comment_like (id) { id -> Int4, @@ -147,37 +111,6 @@ table! { } } -table! { - community_aggregates_fast (id) { - id -> Int4, - name -> Nullable, - title -> Nullable, - icon -> Nullable, - banner -> Nullable, - description -> Nullable, - category_id -> Nullable, - creator_id -> Nullable, - removed -> Nullable, - published -> Nullable, - updated -> Nullable, - deleted -> Nullable, - nsfw -> Nullable, - actor_id -> Nullable, - local -> Nullable, - last_refreshed_at -> Nullable, - creator_actor_id -> Nullable, - creator_local -> Nullable, - creator_name -> Nullable, - creator_preferred_username -> Nullable, - creator_avatar -> Nullable, - category_name -> Nullable, - number_of_subscribers -> Nullable, - number_of_posts -> Nullable, - number_of_comments -> Nullable, - hot_rank -> Nullable, - } -} - table! { community_follower (id) { id -> Int4, @@ -351,52 +284,6 @@ table! { } } -table! { - post_aggregates_fast (id) { - id -> Int4, - name -> Nullable, - url -> Nullable, - body -> Nullable, - creator_id -> Nullable, - community_id -> Nullable, - removed -> Nullable, - locked -> Nullable, - published -> Nullable, - updated -> Nullable, - deleted -> Nullable, - nsfw -> Nullable, - stickied -> Nullable, - embed_title -> Nullable, - embed_description -> Nullable, - embed_html -> Nullable, - thumbnail_url -> Nullable, - ap_id -> Nullable, - local -> Nullable, - creator_actor_id -> Nullable, - creator_local -> Nullable, - creator_name -> Nullable, - creator_preferred_username -> Nullable, - creator_published -> Nullable, - creator_avatar -> Nullable, - banned -> Nullable, - banned_from_community -> Nullable, - community_actor_id -> Nullable, - community_local -> Nullable, - community_name -> Nullable, - community_icon -> Nullable, - community_removed -> Nullable, - community_deleted -> Nullable, - community_nsfw -> Nullable, - number_of_comments -> Nullable, - score -> Nullable, - upvotes -> Nullable, - downvotes -> Nullable, - hot_rank -> Nullable, - hot_rank_active -> Nullable, - newest_activity_time -> Nullable, - } -} - table! { post_like (id) { id -> Int4, @@ -532,30 +419,6 @@ table! { } } -table! { - user_fast (id) { - id -> Int4, - actor_id -> Nullable, - name -> Nullable, - preferred_username -> Nullable, - avatar -> Nullable, - banner -> Nullable, - email -> Nullable, - matrix_user_id -> Nullable, - bio -> Nullable, - local -> Nullable, - admin -> Nullable, - banned -> Nullable, - show_avatars -> Nullable, - send_notifications_to_email -> Nullable, - published -> Nullable, - number_of_posts -> Nullable, - post_score -> Nullable, - number_of_comments -> Nullable, - comment_score -> Nullable, - } -} - table! { user_mention (id) { id -> Int4, @@ -707,13 +570,11 @@ allow_tables_to_appear_in_same_query!( category, comment, comment_aggregates, - comment_aggregates_fast, comment_like, comment_report, comment_saved, community, community_aggregates, - community_aggregates_fast, community_follower, community_moderator, community_user_ban, @@ -729,7 +590,6 @@ allow_tables_to_appear_in_same_query!( password_reset_request, post, post_aggregates, - post_aggregates_fast, post_like, post_read, post_report, @@ -740,7 +600,6 @@ allow_tables_to_appear_in_same_query!( user_, user_aggregates, user_ban, - user_fast, user_mention, comment_alias_1, user_alias_1, diff --git a/migrations/2020-12-17-030456_create_alias_views/down.sql b/migrations/2020-12-17-030456_create_alias_views/down.sql new file mode 100644 index 000000000..66ded96e5 --- /dev/null +++ b/migrations/2020-12-17-030456_create_alias_views/down.sql @@ -0,0 +1 @@ +drop view user_alias_1, user_alias_2, comment_alias_1; diff --git a/migrations/2020-12-17-030456_create_alias_views/up.sql b/migrations/2020-12-17-030456_create_alias_views/up.sql new file mode 100644 index 000000000..3d3b1b430 --- /dev/null +++ b/migrations/2020-12-17-030456_create_alias_views/up.sql @@ -0,0 +1,7 @@ +-- Some view that act as aliases +-- unfortunately necessary, since diesel doesn't have self joins +-- or alias support yet +create view user_alias_1 as select * from user_; +create view user_alias_2 as select * from user_; +create view comment_alias_1 as select * from comment; + diff --git a/migrations/2020-12-17-031053_remove_fast_tables_and_views/down.sql b/migrations/2020-12-17-031053_remove_fast_tables_and_views/down.sql new file mode 100644 index 000000000..1c5d77670 --- /dev/null +++ b/migrations/2020-12-17-031053_remove_fast_tables_and_views/down.sql @@ -0,0 +1,4 @@ +-- There is no restore for this, it would require every view, table, index, etc. +-- If you want to save past this point, you should make a DB backup. + +select * from user_ limit 1; diff --git a/migrations/2020-12-17-031053_remove_fast_tables_and_views/up.sql b/migrations/2020-12-17-031053_remove_fast_tables_and_views/up.sql new file mode 100644 index 000000000..803a5c46f --- /dev/null +++ b/migrations/2020-12-17-031053_remove_fast_tables_and_views/up.sql @@ -0,0 +1,41 @@ +-- Drop views +drop view if exists +comment_aggregates_view, +comment_fast_view, +comment_report_view, +comment_view, +community_aggregates_view, +community_fast_view, +community_follower_view, +community_moderator_view, +community_user_ban_view, +community_view, +mod_add_community_view, +mod_add_view, +mod_ban_from_community_view, +mod_ban_view, +mod_lock_post_view, +mod_remove_comment_view, +mod_remove_community_view, +mod_remove_post_view, +mod_sticky_post_view, +post_aggregates_view, +post_fast_view, +post_report_view, +post_view, +private_message_view, +reply_fast_view, +site_view, +user_mention_fast_view, +user_mention_view, +user_view +cascade; + +-- Drop fast tables +drop table if exists +comment_aggregates_fast, +community_aggregates_fast, +post_aggregates_fast, +user_fast +cascade; +