diff options
author | Vincent Ambo <tazjin@gmail.com> | 2018-05-01T18·00+0200 |
---|---|---|
committer | Vincent Ambo <github@tazj.in> | 2018-05-01T22·33+0200 |
commit | 1d9ff8b4c89b507d33ebdbc35f5e939add67833c (patch) | |
tree | b29c119cdc0eaa2fd1ee8b23f57bce4ebfd070d5 /migrations | |
parent | 02c15f06d6f7864431d22a07bda8a36d8bc30474 (diff) |
fix(migrations): Explicitly insert anonymous user
This guarantees that the anonymous user will always exist and have ID=1.
Diffstat (limited to 'migrations')
-rw-r--r-- | migrations/2018-05-01-141548_add-users/up.sql | 16 |
1 files changed, 11 insertions, 5 deletions
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 |