mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-09-02 11:13:51 +00:00
* Add unique constraint for person(name, instance) (fixes #5045) * fix * not local Co-authored-by: dullbananas <dull.bananas0@gmail.com> --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com>
This commit is contained in:
parent
21c1784a01
commit
cf0e021129
4 changed files with 22 additions and 5 deletions
|
@ -37,7 +37,7 @@ lemmy_db_views_person_content_combined = { workspace = true, features = [
|
|||
lemmy_db_views_search_combined = { workspace = true, features = ["full"] }
|
||||
lemmy_utils = { workspace = true, features = ["full"] }
|
||||
lemmy_db_schema = { workspace = true, features = ["full"] }
|
||||
lemmy_api_utils = { workspace = true }
|
||||
lemmy_api_utils = { workspace = true, features = ["full"] }
|
||||
lemmy_apub_objects = { workspace = true }
|
||||
activitypub_federation = { workspace = true }
|
||||
lemmy_db_schema_file = { workspace = true }
|
||||
|
|
|
@ -91,12 +91,14 @@ mod tests {
|
|||
let pool = &mut context.pool();
|
||||
let data = TestData::create(pool).await?;
|
||||
|
||||
let name = "test_local_user_name";
|
||||
let bio = "test_local_user_bio";
|
||||
|
||||
let creator = LocalUserView::create_test_user(pool, name, bio, false).await?;
|
||||
let regular_user = LocalUserView::create_test_user(pool, name, bio, false).await?;
|
||||
let admin_user = LocalUserView::create_test_user(pool, name, bio, true).await?;
|
||||
let creator =
|
||||
LocalUserView::create_test_user(pool, "test_local_user_name_1", bio, false).await?;
|
||||
let regular_user =
|
||||
LocalUserView::create_test_user(pool, "test_local_user_name_2", bio, false).await?;
|
||||
let admin_user =
|
||||
LocalUserView::create_test_user(pool, "test_local_user_name_3", bio, true).await?;
|
||||
|
||||
let community = Community::create(
|
||||
pool,
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE person
|
||||
DROP CONSTRAINT person_name_instance_unique;
|
||||
|
12
migrations/2025-07-10-105316_username-instance-unique/up.sql
Normal file
12
migrations/2025-07-10-105316_username-instance-unique/up.sql
Normal file
|
@ -0,0 +1,12 @@
|
|||
-- lemmy requires (username + instance_id) to be unique
|
||||
-- delete any existing duplicates
|
||||
DELETE FROM person p1 USING person p2
|
||||
WHERE p1.id > p2.id
|
||||
AND p1.name = p2.name
|
||||
AND p1.instance_id = p2.instance_id
|
||||
AND NOT (p1.local
|
||||
OR p2.local);
|
||||
|
||||
ALTER TABLE person
|
||||
ADD CONSTRAINT person_name_instance_unique UNIQUE (name, instance_id);
|
||||
|
Loading…
Reference in a new issue