· 6 years ago · Oct 01, 2019, 10:42 AM
1create schema public;
2
3comment on schema public is 'standard public schema';
4
5alter schema public owner to charybdis;
6
7create table if not exists alembic_version
8(
9 version_num varchar(32) not null
10 constraint alembic_version_pkc
11 primary key
12);
13
14alter table alembic_version owner to charybdis;
15
16create table if not exists domain
17(
18 created_at timestamp default now(),
19 updated_at timestamp,
20 slug varchar not null
21 constraint domain_slug_key
22 unique,
23 name varchar not null,
24 description text,
25 uuid uuid not null
26 constraint domain_uuid_key
27 unique,
28 is_active boolean,
29 id serial not null
30 constraint domain_pkey
31 primary key
32);
33
34alter table domain owner to charybdis;
35
36create table if not exists permission
37(
38 created_at timestamp default now(),
39 updated_at timestamp,
40 slug varchar not null,
41 id serial not null
42 constraint permission_pkey
43 primary key
44);
45
46alter table permission owner to charybdis;
47
48create table if not exists user_role
49(
50 created_at timestamp default now(),
51 updated_at timestamp,
52 slug varchar not null,
53 id serial not null
54 constraint user_role_pkey
55 primary key
56);
57
58alter table user_role owner to charybdis;
59
60create table if not exists project
61(
62 created_at timestamp default now(),
63 updated_at timestamp,
64 slug varchar not null
65 constraint project_slug_key
66 unique,
67 name varchar not null,
68 description text,
69 uuid uuid,
70 is_active boolean,
71 domain_id integer not null
72 constraint project_domain_id_fkey
73 references domain,
74 id serial not null
75 constraint project_pkey
76 primary key
77);
78
79alter table project owner to charybdis;
80
81create table if not exists "user"
82(
83 created_at timestamp default now(),
84 updated_at timestamp,
85 first_name varchar not null,
86 last_name varchar not null,
87 patronymic varchar,
88 birthday date not null,
89 role_id integer not null
90 constraint user_role_id_fkey
91 references user_role,
92 is_active boolean default true,
93 username varchar
94 constraint user_username_key
95 unique,
96 password_hash varchar,
97 uuid uuid not null,
98 domain_id integer not null
99 constraint user_domain_id_fkey
100 references domain,
101 id serial not null
102 constraint user_pkey
103 primary key
104);
105
106alter table "user" owner to charybdis;
107
108create table if not exists user_permission_linker
109(
110 created_at timestamp default now(),
111 updated_at timestamp,
112 permission_id integer not null
113 constraint user_permission_linker_permission_id_fkey
114 references permission,
115 user_id integer not null
116 constraint user_permission_linker_user_id_fkey
117 references "user",
118 project_id integer not null
119 constraint user_permission_linker_project_id_fkey
120 references project,
121 id serial not null
122 constraint user_permission_linker_pkey
123 primary key,
124 constraint user_permission_linker_permission_id_user_id_project_id_key
125 unique (permission_id, user_id, project_id)
126);
127
128alter table user_permission_linker owner to charybdis;