Fix migration local_image_person (#5799)

This commit is contained in:
Nutomic 2025-06-18 12:56:01 +00:00 committed by GitHub
parent 070d049c49
commit 9a84180b5a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 3 additions and 7 deletions

View file

@ -25,7 +25,7 @@ use {
pub struct LocalImage { pub struct LocalImage {
pub pictrs_alias: String, pub pictrs_alias: String,
pub published_at: DateTime<Utc>, pub published_at: DateTime<Utc>,
pub person_id: PersonId, pub person_id: Option<PersonId>,
/// This means the image is an auto-generated thumbnail, for a post. /// This means the image is an auto-generated thumbnail, for a post.
pub thumbnail_for_post_id: Option<PostId>, pub thumbnail_for_post_id: Option<PostId>,
} }

View file

@ -395,7 +395,7 @@ diesel::table! {
local_image (pictrs_alias) { local_image (pictrs_alias) {
pictrs_alias -> Text, pictrs_alias -> Text,
published_at -> Timestamptz, published_at -> Timestamptz,
person_id -> Int4, person_id -> Nullable<Int4>,
thumbnail_for_post_id -> Nullable<Int4>, thumbnail_for_post_id -> Nullable<Int4>,
} }
} }

View file

@ -5,7 +5,7 @@
-- --
-- See https://github.com/LemmyNet/lemmy/issues/5564 -- See https://github.com/LemmyNet/lemmy/issues/5564
ALTER TABLE local_image ALTER TABLE local_image
ADD COLUMN person_id int NOT NULL DEFAULT 0 REFERENCES person (id) ON UPDATE CASCADE ON DELETE CASCADE, ADD COLUMN person_id int REFERENCES person (id) ON UPDATE CASCADE ON DELETE CASCADE,
ADD COLUMN thumbnail_for_post_id int REFERENCES post (id) ON UPDATE CASCADE ON DELETE CASCADE; ADD COLUMN thumbnail_for_post_id int REFERENCES post (id) ON UPDATE CASCADE ON DELETE CASCADE;
-- Update historical person_id columns -- Update historical person_id columns
@ -19,10 +19,6 @@ FROM
WHERE WHERE
li.local_user_id = lu.id; li.local_user_id = lu.id;
-- Remove the default
ALTER TABLE local_image
ALTER COLUMN person_id DROP DEFAULT;
-- Remove the local_user_id column -- Remove the local_user_id column
ALTER TABLE local_image ALTER TABLE local_image
DROP COLUMN local_user_id; DROP COLUMN local_user_id;