1 -- Following this issue : https://github.com/LemmyNet/lemmy/issues/957
2 -- Creating a unique changeme actor_id
3 CREATE OR REPLACE FUNCTION generate_unique_changeme ()
8 'changeme_' || string_agg(substr('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789', ceil(random() * 62)::integer, 1), '')
10 generate_series(1, 20)
13 -- Need to delete the possible community and user dupes for ones that don't start with the fake one
14 -- A few test inserts, to make sure this removes later dupes
15 -- insert into community (name, title, category_id, creator_id) values ('testcom', 'another testcom', 1, 2);
16 DELETE FROM community a USING (
27 a.actor_id = b.actor_id
30 DELETE FROM user_ a USING (
41 a.actor_id = b.actor_id
44 -- Replacing the current default on the columns, to the unique one
48 actor_id = generate_unique_changeme ()
50 actor_id = 'http://fake.com';
55 actor_id = generate_unique_changeme ()
57 actor_id = 'http://fake.com';
59 -- Add the unique indexes
61 ALTER COLUMN actor_id SET NOT NULL;
64 ALTER COLUMN actor_id SET DEFAULT generate_unique_changeme ();
67 ALTER COLUMN actor_id SET NOT NULL;
70 ALTER COLUMN actor_id SET DEFAULT generate_unique_changeme ();
72 -- Add lowercase uniqueness too
73 DROP INDEX idx_user_name_lower_actor_id;
75 CREATE UNIQUE INDEX idx_user_lower_actor_id ON user_ (lower(actor_id));
77 CREATE UNIQUE INDEX idx_community_lower_actor_id ON community (lower(actor_id));