add email to citizen table

This commit is contained in:
2019-10-08 14:13:31 +02:00
parent afb7f7a1a6
commit ebc552a431
10 changed files with 30 additions and 18 deletions

View File

@@ -2,7 +2,7 @@ do
$$
begin
delete from citizen;
insert into citizen (id, name, birthday, user_id, vote_anonymous, follow_anonymous)
insert into citizen (id, name, birthday, user_id, vote_anonymous, follow_anonymous, email)
select
uuid_in(md5('citizen'||row_number() over ()::text)::cstring),
jsonb_build_object(
@@ -13,7 +13,8 @@ begin
now() - interval '25 years',
u.id,
row_number() over () % 3 = 0,
row_number() over () % 5 = 1
row_number() over () % 5 = 1,
u.username || '@domain'|| (row_number() over () % 5 = 1) || '.com'
from "user" u;
raise notice 'citizen fixtures done';

View File

@@ -7,21 +7,23 @@ declare
begin
select insert_user(resource->'user') into inserted_user;
insert into citizen (id, name, birthday, user_id, vote_anonymous, follow_anonymous)
insert into citizen (id, name, birthday, user_id, vote_anonymous, follow_anonymous, email)
select
coalesce(id, uuid_generate_v4()),
name,
birthday,
(inserted_user->>'id')::uuid,
coalesce(vote_anonymous, true),
coalesce(follow_anonymous, true)
coalesce(follow_anonymous, true),
email
from json_populate_record(null::citizen, resource)
on conflict (id) do update set
name = excluded.name,
birthday = excluded.birthday,
user_id = excluded.user_id,
vote_anonymous = excluded.vote_anonymous,
follow_anonymous = excluded.follow_anonymous
follow_anonymous = excluded.follow_anonymous,
email = excluded.email
returning id into new_id;
select find_citizen_by_id_with_user(new_id) into resource;

View File

@@ -4,21 +4,23 @@ $$
declare
new_id uuid;
begin
insert into citizen (id, name, birthday, user_id, vote_anonymous, follow_anonymous)
insert into citizen (id, name, birthday, user_id, vote_anonymous, follow_anonymous, email)
select
coalesce(id, uuid_generate_v4()),
name,
birthday,
(resource#>>'{user, id}')::uuid,
coalesce(vote_anonymous, true),
coalesce(follow_anonymous, true)
coalesce(follow_anonymous, true),
email
from json_populate_record(null::citizen, resource)
on conflict (id) do update set
name = excluded.name,
birthday = excluded.birthday,
user_id = excluded.user_id,
vote_anonymous = excluded.vote_anonymous,
follow_anonymous = excluded.follow_anonymous
follow_anonymous = excluded.follow_anonymous,
email = excluded.email
returning id into new_id;
select find_citizen_by_id(new_id) into resource;

View File

@@ -18,7 +18,8 @@ create table citizen
birthday date not null,
user_id uuid not null references "user" (id) unique,
vote_anonymous boolean default true not null,
follow_anonymous boolean default true not null
follow_anonymous boolean default true not null,
email text not null check ( email ~* '.+@.+\..+' )
);
create table workgroup

View File

@@ -4,7 +4,7 @@ declare
created_user json := '{"username": "george", "plain_password": "azerty", "roles": ["ROLE_USER"]}';
_user_id uuid;
_citizen_id uuid;
created_citizen json := '{"name": {"first_name":"George", "last_name":"MICHEL"}, "birthday": "2001-01-01"}';
created_citizen json := '{"name": {"first_name":"George", "last_name":"MICHEL"}, "birthday": "2001-01-01", "email":"george.michel@gmail.com"}';
created_article json := '{"version_id":"933b6a1b-50c9-42b6-989f-c02a57814ef9", "title": "Love the world", "anonymous": false, "content": "bla bal bla", "tags": ["love", "test"], "draft":false}';
created_article_v2 json;
first_article_id uuid;

View File

@@ -4,8 +4,8 @@ declare
wrong_citizen json;
created_user json := '{"username": "george", "plain_password": "azerty", "roles": ["ROLE_USER"]}';
_user_id uuid;
created_citizen json := '{"name": {"first_name":"George", "last_name":"MICHEL"}, "birthday": "2001-01-01"}';
created_citizen_with_user json := '{"name": {"first_name":"George", "last_name":"MICHEL"}, "birthday": "2001-01-01", "user":{"username": "george junior", "plain_password": "azerty", "roles": ["ROLE_USER"]}}';
created_citizen json := '{"name": {"first_name":"George", "last_name":"MICHEL"}, "birthday": "2001-01-01", "email":"george.michel@gmail.com"}';
created_citizen_with_user json := '{"name": {"first_name":"George", "last_name":"MICHEL"}, "birthday": "2001-01-01", "email":"george.michel@gmail.com", "user":{"username": "george junior", "plain_password": "azerty", "roles": ["ROLE_USER"]}}';
selected_citizen json;
begin
-- insert user for context

View File

@@ -10,7 +10,8 @@ declare
"first_name": "George",
"last_name": "MICHEL"
},
"birthday": "2001-01-01"
"birthday": "2001-01-01",
"email":"george.michel@gmail.com"
}
$json$;
created_article json := $json$

View File

@@ -10,7 +10,8 @@ declare
"first_name": "George",
"last_name": "MICHEL"
},
"birthday": "2001-01-01"
"birthday": "2001-01-01",
"email":"george.michel@gmail.com"
}
$json$;
created_article json := $json$

View File

@@ -11,7 +11,8 @@ declare
"first_name": "George",
"last_name": "MICHEL"
},
"birthday": "2001-01-01"
"birthday": "2001-01-01",
"email":"george.michel@gmail.com"
}
$json$;
created_citizen2 json := $json$
@@ -20,7 +21,8 @@ declare
"first_name": "John",
"last_name": "Doe"
},
"birthday": "2002-01-01"
"birthday": "2002-01-01",
"email":"george.michel@gmail.com"
}
$json$;
begin

View File

@@ -11,7 +11,8 @@ declare
"first_name": "George",
"last_name": "MICHEL"
},
"birthday": "2001-01-01"
"birthday": "2001-01-01",
"email":"george.michel@gmail.com"
}
$json$;
created_citizen2 json := $json$
@@ -20,7 +21,8 @@ declare
"first_name": "George2",
"last_name": "MICHEL2"
},
"birthday": "2001-01-02"
"birthday": "2001-01-02",
"email":"george.michel@gmail.com"
}
$json$;
created_article json := $json$