From f203abd4e1d9a58b7ee7968668b007a292edabec Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 8 Jun 2023 09:24:34 -0400 Subject: [PATCH] Fixing post.url migration. --- crates/db_schema/src/schema.rs | 3 ++- migrations/2023-06-06-104440_index_post_url/down.sql | 4 ++++ migrations/2023-06-06-104440_index_post_url/up.sql | 8 ++++++++ src/scheduled_tasks.rs | 2 -- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 30697d053..ac4ddc47a 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -636,7 +636,8 @@ diesel::table! { id -> Int4, #[max_length = 200] name -> Varchar, - url -> Nullable, + #[max_length = 512] + url -> Nullable, body -> Nullable, creator_id -> Int4, community_id -> Int4, diff --git a/migrations/2023-06-06-104440_index_post_url/down.sql b/migrations/2023-06-06-104440_index_post_url/down.sql index 5a60b131b..ccc9e938f 100644 --- a/migrations/2023-06-06-104440_index_post_url/down.sql +++ b/migrations/2023-06-06-104440_index_post_url/down.sql @@ -1 +1,5 @@ +-- Change back the column type +alter table post alter column url type text; + +-- Drop the index drop index idx_post_url; diff --git a/migrations/2023-06-06-104440_index_post_url/up.sql b/migrations/2023-06-06-104440_index_post_url/up.sql index 4f8ea66ff..ce3532887 100644 --- a/migrations/2023-06-06-104440_index_post_url/up.sql +++ b/migrations/2023-06-06-104440_index_post_url/up.sql @@ -1 +1,9 @@ +-- Make a hard limit of 512 for the post.url column +-- Truncate existing long rows. +update post set url = left(url, 512) where length(url) > 512; + +-- Enforce the limit +alter table post alter column url type varchar (512); + +-- Add the index create index idx_post_url on post(url); diff --git a/src/scheduled_tasks.rs b/src/scheduled_tasks.rs index 40a19b66b..e41ccc9ee 100644 --- a/src/scheduled_tasks.rs +++ b/src/scheduled_tasks.rs @@ -72,8 +72,6 @@ pub fn setup(db_url: String, user_agent: String) -> Result<(), LemmyError> { /// Update the hot_rank columns for the aggregates tables fn update_hot_ranks(conn: &mut PgConnection, last_week_only: bool) { - info!("Updating hot ranks..."); - let mut post_update = diesel::update(post_aggregates::table).into_boxed(); let mut comment_update = diesel::update(comment_aggregates::table).into_boxed(); let mut community_update = diesel::update(community_aggregates::table).into_boxed();