· 10 years ago · Sep 03, 2016, 09:22 PM
1create table if not exists
2 program (
3 id bigserial primary key,
4 name text not null,
5-- author text not null references basic_auth.users (email)
6-- on delete restrict on update cascade
7-- default basic_auth.current_email(),
8 code text not null,
9 created_at timestamptz not null default current_time
10);
11
12
13create table if not exists
14 form (
15 id bigserial primary key,
16 name text not null,
17 description text not null,
18-- author text not null references basic_auth.users (email)
19-- on delete restrict on update cascade
20-- default basic_auth.current_email(),
21 code text not null,
22 scope text not null,
23 args text [2] []
24
25);
26
27create table if not exists
28 scope (
29 id bigserial primary key,
30 program bigserial not null references program (id) on delete restrict on update cascade,
31 scope_program bigserial not null references program (id) on delete restrict on update cascade
32);
33
34insert into program values
35 (DEFAULT, 'name1', 'qwe', DEFAULT),
36 (DEFAULT, 'name2', 'qwe', DEFAULT),
37 (DEFAULT, 'name3', 'qwe', DEFAULT),
38 (DEFAULT, 'name4', 'qwe', DEFAULT);
39
40
41insert into scope values
42(default, 1, 2),
43(default, 1, 3),
44(default, 1, 4);
45
46select scope_program from program
47join scope on scope.program = program.id;