lemmy icon indicating copy to clipboard operation
lemmy copied to clipboard

Fresh Lemmy initial code migrations fail if setup.site_name in lemmy.hjson is longer than 20 characters

Open JustinLex opened this issue 2 years ago • 6 comments

  • [x] Did you check to see if this issue already exists?
  • [x] Is this only a single bug? Do not put multiple bugs in one issue.
  • [ ] Is this a question or discussion? Don't use this, use https://lemmy.ml/c/lemmy_support .
  • [ ] Is this a UI / front end issue? Use the lemmy-ui repo.

Issue Summary

When Installing a new Lemmy instance, my backend container crashloops during the initial code migration because of duplicate user constraints.

Lemmy's log errors with either thread 'main' panicked at 'couldnt create local user: DatabaseError(UniqueViolation, "duplicate key value violates unique constraint \"local_user_email_key\"")', crates/db_schema/src/impls/local_user.rs:157:8 or thread 'main' panicked at 'couldnt create local user: DatabaseError(UniqueViolation, "duplicate key value violates unique constraint \"local_user_person_id_key\"")', crates/db_schema/src/impls/local_user.rs:157:8, depending on if lemmy.hjson includes an admin email.

The issue goes away if I use a site_name shorter than 20 characters.

Steps to Reproduce

I created a new Lemmy with a setup.site_name in lemmy.hjson longer than 20 characters.

Technical details

log from lemmy when admin email is set:

2023-06-10T11:42:33.144023Z  INFO lemmy_db_schema::utils: Running Database migrations (This may take a long time)...
2023-06-10T11:42:33.146201Z  INFO lemmy_db_schema::utils: Database migrations complete.
2023-06-10T11:42:33.153222Z  INFO lemmy_server::code_migrations: Running user_updates_2020_04_02
2023-06-10T11:42:33.155309Z  INFO lemmy_server::code_migrations: 0 person rows updated.
2023-06-10T11:42:33.155502Z  INFO lemmy_server::code_migrations: Running community_updates_2020_04_02
2023-06-10T11:42:33.157100Z  INFO lemmy_server::code_migrations: 0 community rows updated.
2023-06-10T11:42:33.157179Z  INFO lemmy_server::code_migrations: Running post_updates_2020_04_03
2023-06-10T11:42:33.158363Z  INFO lemmy_server::code_migrations: 0 post rows updated.
2023-06-10T11:42:33.158441Z  INFO lemmy_server::code_migrations: Running comment_updates_2020_04_03
2023-06-10T11:42:33.161567Z  INFO lemmy_server::code_migrations: 0 comment rows updated.
2023-06-10T11:42:33.161649Z  INFO lemmy_server::code_migrations: Running private_message_updates_2020_05_05
2023-06-10T11:42:33.162290Z  INFO lemmy_server::code_migrations: 0 private message rows updated.
2023-06-10T11:42:33.162362Z  INFO lemmy_server::code_migrations: Running post_thumbnail_url_updates_2020_07_27
2023-06-10T11:42:33.162752Z  INFO lemmy_server::code_migrations: 0 Post thumbnail_url rows updated.
2023-06-10T11:42:33.162849Z  INFO lemmy_server::code_migrations: Running apub_columns_2021_02_02
2023-06-10T11:42:33.163284Z  INFO lemmy_server::code_migrations: Running instance_actor_2021_09_29
2023-06-10T11:42:33.166781Z  INFO lemmy_server::code_migrations: Running regenerate_public_keys_2022_07_05
2023-06-10T11:42:33.167247Z  INFO lemmy_server::code_migrations: Running initialize_local_site_2022_10_10
2023-06-10T11:42:33.167541Z  INFO lemmy_server::code_migrations: No Local Site found, creating it.
thread 'main' panicked at 'couldnt create local user: DatabaseError(UniqueViolation, "duplicate key value violates unique constraint \"local_user_email_key\"")', crates/db_schema/src/impls/local_user.rs:157:8
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

log from lemmy when admin email is not set:

2023-06-10T11:46:34.889250Z  INFO lemmy_db_schema::utils: Running Database migrations (This may take a long time)...
2023-06-10T11:46:34.891222Z  INFO lemmy_db_schema::utils: Database migrations complete.
2023-06-10T11:46:34.899871Z  INFO lemmy_server::code_migrations: Running user_updates_2020_04_02
2023-06-10T11:46:34.902106Z  INFO lemmy_server::code_migrations: 0 person rows updated.
2023-06-10T11:46:34.902351Z  INFO lemmy_server::code_migrations: Running community_updates_2020_04_02
2023-06-10T11:46:34.936512Z  INFO lemmy_server::code_migrations: 0 community rows updated.
2023-06-10T11:46:34.938051Z  INFO lemmy_server::code_migrations: Running post_updates_2020_04_03
2023-06-10T11:46:34.947307Z  INFO lemmy_server::code_migrations: 0 post rows updated.
2023-06-10T11:46:34.947447Z  INFO lemmy_server::code_migrations: Running comment_updates_2020_04_03
2023-06-10T11:46:34.962643Z  INFO lemmy_server::code_migrations: 0 comment rows updated.
2023-06-10T11:46:34.967547Z  INFO lemmy_server::code_migrations: Running private_message_updates_2020_05_05
2023-06-10T11:46:35.010423Z  INFO lemmy_server::code_migrations: 0 private message rows updated.
2023-06-10T11:46:35.010604Z  INFO lemmy_server::code_migrations: Running post_thumbnail_url_updates_2020_07_27
2023-06-10T11:46:35.011322Z  INFO lemmy_server::code_migrations: 0 Post thumbnail_url rows updated.
2023-06-10T11:46:35.011431Z  INFO lemmy_server::code_migrations: Running apub_columns_2021_02_02
2023-06-10T11:46:35.011926Z  INFO lemmy_server::code_migrations: Running instance_actor_2021_09_29
2023-06-10T11:46:35.043901Z  INFO lemmy_server::code_migrations: Running regenerate_public_keys_2022_07_05
2023-06-10T11:46:35.044846Z  INFO lemmy_server::code_migrations: Running initialize_local_site_2022_10_10
2023-06-10T11:46:35.045237Z  INFO lemmy_server::code_migrations: No Local Site found, creating it.
thread 'main' panicked at 'couldnt create local user: DatabaseError(UniqueViolation, "duplicate key value violates unique constraint \"local_user_person_id_key\"")', crates/db_schema/src/impls/local_user.rs:157:8
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Log from postgres:

2023-06-10 11:12:00.262 UTC [308] FATAL:  no pg_hba.conf entry for host "10.4.81.251", user "lemmy", database "lemmy", SSL encryption
2023-06-10 11:12:05.062 UTC [322] ERROR:  value too long for type character varying(20)
2023-06-10 11:12:05.062 UTC [322] STATEMENT:  INSERT INTO "site" ("name", "sidebar", "updated", "icon", "banner", "description", "actor_id", "last_refreshed_at", "inbox_url", "private_key", "public_key", "instance_id") VALUES ($1, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, $2, $3, $4, $5, $6, $7) ON CONFLICT ("actor_id") DO UPDATE SET "name" = $8, "actor_id" = $9, "last_refreshed_at" = $10, "inbox_url" = $11, "private_key" = $12, "public_key" = $13, "instance_id" = $14 RETURNING "site"."id", "site"."name", "site"."sidebar", "site"."published", "site"."updated", "site"."icon", "site"."banner", "site"."description", "site"."actor_id", "site"."last_refreshed_at", "site"."inbox_url", "site"."private_key", "site"."public_key", "site"."instance_id"
2023-06-10 11:12:05.062 UTC [322] LOG:  could not receive data from client: Connection reset by peer
2023-06-10 11:12:06.768 UTC [323] FATAL:  no pg_hba.conf entry for host "10.4.81.251", user "lemmy", database "lemmy", SSL encryption
2023-06-10 11:12:07.046 UTC [325] ERROR:  duplicate key value violates unique constraint "local_user_email_key"
2023-06-10 11:12:07.046 UTC [325] DETAIL:  Key (email)=([email protected]) already exists.
2023-06-10 11:12:07.046 UTC [325] STATEMENT:  INSERT INTO "local_user" ("person_id", "password_encrypted", "email", "show_nsfw", "theme", "default_sort_type", "default_listing_type", "interface_language", "show_avatars", "send_notifications_to_email", "show_bot_accounts", "show_scores", "show_read_posts", "show_new_post_notifs", "email_verified", "accepted_application") VALUES ($1, $2, $3, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT) RETURNING "local_user"."id", "local_user"."person_id", "local_user"."password_encrypted", "local_user"."email", "local_user"."show_nsfw", "local_user"."theme", "local_user"."default_sort_type", "local_user"."default_listing_type", "local_user"."interface_language", "local_user"."show_avatars", "local_user"."send_notifications_to_email", "local_user"."validator_time", "local_user"."show_bot_accounts", "local_user"."show_scores", "local_user"."show_read_posts", "local_user"."show_new_post_notifs", "local_user"."email_verified", "local_user"."accepted_application"
2023-06-10 11:12:07.051 UTC [325] LOG:  could not receive data from client: Connection reset by peer

(timestamps don't match up between logs because I recreated the bugs a few times to get complete logs)

I recreated this with both dessalines/lemmy:0.17.4-rc.5 and dessalines/lemmy:0.17.3 docker images, these logs are from dessalines/lemmy:0.17.4-rc.5.

I am running Lemmy in containers on Kubernetes, and the database was set up with Crunchy PGO with a lemmy user/db and SSL disabled.

JustinLex avatar Jun 10 '23 11:06 JustinLex

I spent half an hour trying to find the problem...

Thank you

TheFrenchGhosty avatar Jun 11 '23 14:06 TheFrenchGhosty

Can confirm that is also happening with a fresh Docker installation on 0.17.3. Lemmy user/db, SSL enabled IIRC.

Shadark avatar Jun 11 '23 19:06 Shadark

@TheFrenchGhosty No problem! It definitely took me longer than that to understand why my production installation was failing when my test installation went so well 🥲

Devs, looking forward to finding out if this is intended behavior, and if there should be documentation on this, but I understand that this isn't urgent.

JustinLex avatar Jun 12 '23 01:06 JustinLex

Same.

adamboutcher avatar Jun 16 '23 11:06 adamboutcher

Having the same issue on new installation via docker. Changing the site name to less than 20 characters allowed me to finish the reinstall after database reset.

geoffcorey avatar Jun 19 '23 13:06 geoffcorey

I'm using Lemmy Easy Deploy and have a similar issue.

I shortened my site name considerably (it was 22 chars). I still have the issue, but in relation to a different key value:

duplicate key value violates unique constraint "idx_person_lower_actor_id"

This happens immediately after the migrations log states No Local Site found, creating it. and then it goes into an infinite loop trying to run migrations and hitting the same idx_person_lower_actor_id error. So the Lemmy backend container gets stuck in a constant "Restarting" loop.

I've found multiple people with a similar "duplicate key value" issue, but none of them relating to idx_person_lower_actor_id. I've even tried changing the Lemmy admin in the config.env to no avail.


Edit: For anyone else that runs into a similar issue, make sure to delete the .live directory before trying to do a fresh install using Lemmy Easy Deploy. I forgot to remove that and the duplicate key issue was because it was trying to carry out migrations for tables that already had values set.

bloqhead avatar Jul 07 '23 19:07 bloqhead