fix(migrations): Explicitly insert anonymous user

This guarantees that the anonymous user will always exist and have
ID=1.
This commit is contained in:
Vincent Ambo 2018-05-01 20:00:43 +02:00 committed by Vincent Ambo
parent 02c15f06d6
commit 1d9ff8b4c8

View file

@ -8,11 +8,17 @@ CREATE TABLE users (
admin BOOLEAN NOT NULL DEFAULT false admin BOOLEAN NOT NULL DEFAULT false
); );
INSERT INTO users (email, name) -- Insert the 'anonymous' user explicitly:
SELECT author_email AS email, 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 author_name AS name
FROM posts FROM posts
GROUP BY name, email; WHERE author_email != 'anonymous@nothing.org'
GROUP BY name, email;
-- Create the 'author' column in the relevant tables (initially -- Create the 'author' column in the relevant tables (initially
-- without a not-null constraint) and populate it with the data -- without a not-null constraint) and populate it with the data