fix(migrations): Explicitly insert anonymous user
This guarantees that the anonymous user will always exist and have ID=1.
This commit is contained in:
parent
02c15f06d6
commit
1d9ff8b4c8
1 changed files with 11 additions and 5 deletions
|
@ -8,11 +8,17 @@ CREATE TABLE users (
|
|||
admin BOOLEAN NOT NULL DEFAULT false
|
||||
);
|
||||
|
||||
INSERT INTO users (email, name)
|
||||
SELECT author_email AS email,
|
||||
-- Insert the 'anonymous' user explicitly:
|
||||
INSERT INTO users (name, email)
|
||||
VALUES ('Anonymous', 'anonymous@nothing.org');
|
||||
|
||||
INSERT INTO users (id, email, name)
|
||||
SELECT nextval('users_id_seq'),
|
||||
author_email AS email,
|
||||
author_name AS name
|
||||
FROM posts
|
||||
GROUP BY name, email;
|
||||
FROM posts
|
||||
WHERE author_email != 'anonymous@nothing.org'
|
||||
GROUP BY name, email;
|
||||
|
||||
-- Create the 'author' column in the relevant tables (initially
|
||||
-- without a not-null constraint) and populate it with the data
|
||||
|
|
Loading…
Reference in a new issue