merge #19: Create fixtures for all tables
This commit is contained in:
17
resources/sql/fixtures/01-user.sql
Normal file
17
resources/sql/fixtures/01-user.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
do
|
||||
$$
|
||||
declare
|
||||
_password text := crypt('azerty', gen_salt('bf', 8));
|
||||
begin
|
||||
delete from "user";
|
||||
insert into "user" (username, password, blocked_at)
|
||||
select
|
||||
'username' || s,
|
||||
_password,
|
||||
case when s % 10 = 0 then now() else null end
|
||||
from generate_series(1, 1000) s;
|
||||
|
||||
raise notice 'user fixtures done';
|
||||
end;
|
||||
$$;
|
||||
|
||||
21
resources/sql/fixtures/02-citizen.sql
Normal file
21
resources/sql/fixtures/02-citizen.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
do
|
||||
$$
|
||||
begin
|
||||
delete from citizen;
|
||||
insert into citizen (name, birthday, user_id, vote_annonymous, follow_annonymous)
|
||||
select
|
||||
jsonb_build_object(
|
||||
'first_name', 'first name' || row_number() over (),
|
||||
'last_name', 'LAST NAME' || row_number() over (),
|
||||
'civility', 'm'
|
||||
),
|
||||
now() - interval '25 years',
|
||||
u.id,
|
||||
row_number() over () % 3 = 0,
|
||||
row_number() over () % 5 = 1
|
||||
from "user" u;
|
||||
|
||||
raise notice 'citizen fixtures done';
|
||||
end;
|
||||
$$;
|
||||
|
||||
26
resources/sql/fixtures/03-workgroup.sql
Normal file
26
resources/sql/fixtures/03-workgroup.sql
Normal file
@@ -0,0 +1,26 @@
|
||||
do
|
||||
$$
|
||||
begin
|
||||
delete from citizen_in_workgroup;
|
||||
delete from workgroup;
|
||||
|
||||
insert into workgroup (created_by_id, name, description, annonymous, owner_id)
|
||||
select
|
||||
z.id,
|
||||
'name' || rn,
|
||||
'description' || rn,
|
||||
rn % 3 = 1,
|
||||
z.id
|
||||
from (select *, row_number() over () rn from citizen) z;
|
||||
|
||||
insert into citizen_in_workgroup (citizen_id, workgroup_id)
|
||||
select
|
||||
z.id,
|
||||
w.id
|
||||
from (select *, row_number() over ()+5 % 1000 rn from citizen) z
|
||||
join (select *, row_number() over () rn from workgroup) w using (rn);
|
||||
|
||||
raise notice 'workgroup fixtures done';
|
||||
end;
|
||||
$$;
|
||||
|
||||
37
resources/sql/fixtures/04-article.sql
Normal file
37
resources/sql/fixtures/04-article.sql
Normal file
@@ -0,0 +1,37 @@
|
||||
do
|
||||
$$
|
||||
declare
|
||||
_tags text[] = $tags$
|
||||
{
|
||||
"nature", "green", "sky",
|
||||
"nuclear", "oil", "black",
|
||||
"love", "human", "scuirel"
|
||||
}
|
||||
$tags$;
|
||||
begin
|
||||
delete from article_relations;
|
||||
delete from article;
|
||||
|
||||
insert into article (version_id, created_by_id, title, annonymous, content, description, tags)
|
||||
select
|
||||
uuid_generate_v4(),
|
||||
z.id,
|
||||
'title' || row_number() over (),
|
||||
row_number() over () % 3 = 0,
|
||||
'content' || row_number() over (),
|
||||
'description' || row_number() over (),
|
||||
_tags[(row_number() over () % 5):(row_number() over () % 9)]
|
||||
from citizen z;
|
||||
|
||||
insert into article_relations (source_id, target_id, created_by_id)
|
||||
select
|
||||
src.id,
|
||||
dest.id,
|
||||
src.created_by_id
|
||||
from (select *, row_number() over () rn from article, lateral generate_series(1, 5) g) src
|
||||
join (select *, row_number() over () +5 rn from article) dest using (rn);
|
||||
|
||||
raise notice 'article fixtures done';
|
||||
end;
|
||||
$$;
|
||||
|
||||
38
resources/sql/fixtures/05-constitution.sql
Normal file
38
resources/sql/fixtures/05-constitution.sql
Normal file
@@ -0,0 +1,38 @@
|
||||
do
|
||||
$$
|
||||
begin
|
||||
delete from article_in_title;
|
||||
delete from title;
|
||||
delete from constitution;
|
||||
|
||||
insert into constitution (version_id, created_by_id, title, annonymous)
|
||||
select
|
||||
uuid_generate_v4(),
|
||||
z.id,
|
||||
'title' || row_number() over (),
|
||||
row_number() over () % 3 = 0
|
||||
from citizen z;
|
||||
|
||||
insert into title (created_by_id, name, rank, constitution_id)
|
||||
select
|
||||
c.created_by_id,
|
||||
'name' || row_number() over (),
|
||||
row_number() over (),
|
||||
c.id
|
||||
from constitution c,
|
||||
lateral generate_series(1, 5) g;
|
||||
|
||||
insert into article_in_title (created_by_id, rank, title_id, article_id, constitution_id)
|
||||
select
|
||||
ti.created_by_id,
|
||||
row_number() over (),
|
||||
ti.id,
|
||||
a.id,
|
||||
ti.constitution_id
|
||||
from (select *, (row_number() over () % 1005) rn from title, lateral generate_series(1, 3) g) ti
|
||||
join (select *, row_number() over () rn from article) a using (rn);
|
||||
|
||||
raise notice 'constitution fixtures done';
|
||||
end;
|
||||
$$;
|
||||
|
||||
30
resources/sql/fixtures/06-follow.sql
Normal file
30
resources/sql/fixtures/06-follow.sql
Normal file
@@ -0,0 +1,30 @@
|
||||
do
|
||||
$$
|
||||
begin
|
||||
delete from follow;
|
||||
|
||||
insert into follow_article (citizen_id, target_id)
|
||||
select
|
||||
z.id,
|
||||
a.id
|
||||
from (select *, row_number() over () % 995 rn from citizen, lateral generate_series(1, 5)) z
|
||||
join (select *, row_number() over () rn from article) a using (rn);
|
||||
|
||||
insert into follow_constitution (citizen_id, target_id)
|
||||
select
|
||||
z.id,
|
||||
a.id
|
||||
from (select *, row_number() over () % 995 rn from citizen, lateral generate_series(1, 5)) z
|
||||
join (select *, row_number() over () rn from constitution) a using (rn);
|
||||
|
||||
insert into follow_citizen (citizen_id, target_id)
|
||||
select
|
||||
z.id,
|
||||
a.id
|
||||
from (select *, row_number() over () % 995 rn from citizen, lateral generate_series(1, 5)) z
|
||||
join (select *, row_number() over () rn from citizen) a using (rn);
|
||||
|
||||
raise notice 'follow fixtures done';
|
||||
end;
|
||||
$$;
|
||||
|
||||
43
resources/sql/fixtures/07-comment.sql
Normal file
43
resources/sql/fixtures/07-comment.sql
Normal file
@@ -0,0 +1,43 @@
|
||||
do
|
||||
$$
|
||||
begin
|
||||
delete from comment;
|
||||
|
||||
insert into comment_on_article (citizen_id, target_id, content)
|
||||
select
|
||||
z.id,
|
||||
a.id,
|
||||
'content' || (row_number() over () * g)
|
||||
from (select *, row_number() over () % 995 rn from citizen, lateral generate_series(1, 5) g) z
|
||||
join (select *, row_number() over () rn from article) a using (rn);
|
||||
|
||||
insert into comment_on_article (citizen_id, target_id, content, parent_id)
|
||||
select
|
||||
z.id,
|
||||
a.target_id,
|
||||
'content' || row_number() over () * g,
|
||||
a.id
|
||||
from (select *, row_number() over () % 995 rn from citizen, lateral generate_series(1, 5) g) z
|
||||
join (select *, row_number() over () rn from comment_on_article) a using (rn);
|
||||
|
||||
insert into comment_on_article (citizen_id, target_id, content, parent_id)
|
||||
select
|
||||
z.id,
|
||||
a.target_id,
|
||||
'content' || row_number() over () * g,
|
||||
a.id
|
||||
from (select *, row_number() over () % 995 rn from citizen, lateral generate_series(1, 5) g) z
|
||||
join (select *, row_number() over () rn from comment_on_article where parent_id is not null) a using (rn);
|
||||
|
||||
insert into comment_on_constitution (citizen_id, target_id, content)
|
||||
select
|
||||
z.id,
|
||||
a.id,
|
||||
'content' || row_number() over () * g
|
||||
from (select *, row_number() over () % 995 rn from citizen, lateral generate_series(1, 5) g) z
|
||||
join (select *, row_number() over () rn from constitution) a using (rn);
|
||||
|
||||
raise notice 'comment fixtures done';
|
||||
end;
|
||||
$$;
|
||||
|
||||
48
resources/sql/fixtures/08-vote.sql
Normal file
48
resources/sql/fixtures/08-vote.sql
Normal file
@@ -0,0 +1,48 @@
|
||||
do
|
||||
$$
|
||||
begin
|
||||
delete from vote_for_article;
|
||||
delete from vote_for_constitution;
|
||||
delete from vote_for_comment_on_article;
|
||||
delete from vote_for_comment_on_constitution;
|
||||
|
||||
insert into vote_for_article (citizen_id, target_id, note, anonymous)
|
||||
select
|
||||
z.id,
|
||||
a.id,
|
||||
(row_number() over () % 3) -1,
|
||||
(row_number() over () % 3 = 1)
|
||||
from (select *, row_number() over () % 995 rn, g from citizen, lateral generate_series(1, 10) g) z
|
||||
join (select *, row_number() over () rn from article) a using (rn);
|
||||
|
||||
insert into vote_for_constitution (citizen_id, target_id, note, anonymous)
|
||||
select
|
||||
z.id,
|
||||
a.id,
|
||||
(row_number() over () % 3) -1,
|
||||
(row_number() over () % 3 = 1)
|
||||
from (select *, row_number() over () % 995 rn, g from citizen, lateral generate_series(1, 5) g) z
|
||||
join (select *, row_number() over () rn from constitution) a using (rn);
|
||||
|
||||
insert into vote_for_comment_on_article (citizen_id, target_id, note, anonymous)
|
||||
select
|
||||
z.id,
|
||||
a.id,
|
||||
(row_number() over () % 3) -1,
|
||||
(row_number() over () % 3 = 1)
|
||||
from (select *, row_number() over () % 995 rn, g from citizen, lateral generate_series(1, 3) g) z
|
||||
join (select *, row_number() over () rn from comment_on_article) a using (rn);
|
||||
|
||||
insert into vote_for_comment_on_constitution (citizen_id, target_id, note, anonymous)
|
||||
select
|
||||
z.id,
|
||||
a.id,
|
||||
(row_number() over () % 3) -1,
|
||||
(row_number() over () % 3 = 1)
|
||||
from (select *, row_number() over () % 995 rn, g from citizen, lateral generate_series(1, 2) g) z
|
||||
join (select *, row_number() over () rn from comment_on_constitution) a using (rn);
|
||||
|
||||
raise notice 'vote fixtures done';
|
||||
end;
|
||||
$$;
|
||||
|
||||
7
resources/sql/functions/helpers/random_between.sql
Normal file
7
resources/sql/functions/helpers/random_between.sql
Normal file
@@ -0,0 +1,7 @@
|
||||
CREATE OR REPLACE FUNCTION random_between(low INT ,high INT)
|
||||
RETURNS INT AS
|
||||
$$
|
||||
BEGIN
|
||||
RETURN floor(random()* (high-low + 1) + low);
|
||||
END;
|
||||
$$ language 'plpgsql' STRICT;
|
||||
@@ -37,10 +37,10 @@ create table workgroup
|
||||
|
||||
create table citizen_in_workgroup
|
||||
(
|
||||
citizen_id uuid not null references citizen (id),
|
||||
workgroup uuid not null references workgroup (id),
|
||||
created_at timestamptz default now() not null,
|
||||
primary key (citizen_id, workgroup)
|
||||
citizen_id uuid not null references citizen (id),
|
||||
workgroup_id uuid not null references workgroup (id),
|
||||
created_at timestamptz default now() not null,
|
||||
primary key (citizen_id, workgroup_id)
|
||||
);
|
||||
|
||||
create table moderator
|
||||
|
||||
Reference in New Issue
Block a user