From 1d9ff8b4c89b507d33ebdbc35f5e939add67833c Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 1 May 2018 20:00:43 +0200 Subject: fix(migrations): Explicitly insert anonymous user This guarantees that the anonymous user will always exist and have ID=1. --- migrations/2018-05-01-141548_add-users/up.sql | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'migrations/2018-05-01-141548_add-users/up.sql') diff --git a/migrations/2018-05-01-141548_add-users/up.sql b/migrations/2018-05-01-141548_add-users/up.sql index 222afc485afe..5fadeeb23a00 100644 --- a/migrations/2018-05-01-141548_add-users/up.sql +++ b/migrations/2018-05-01-141548_add-users/up.sql @@ -8,11 +8,17 @@ CREATE TABLE users ( admin BOOLEAN NOT NULL DEFAULT false ); -INSERT INTO users (email, name) -SELECT author_email AS email, - author_name AS name -FROM posts -GROUP BY name, 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 + 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 -- cgit 1.4.1