init.sql 1.4 KB
Newer Older
1
2
3
4
5
6
CREATE EXTENSION IF NOT EXISTS ltree;

CREATE TABLE gms_group (
  id varchar NOT NULL,
  name text NOT NULL,
  path ltree NOT NULL,
7
  is_leaf boolean,
8
9
10
11
  primary key(id)
);

CREATE INDEX group_path_gist_idx ON gms_group USING GIST(path);
12
CREATE UNIQUE INDEX group_path_idx ON gms_group USING btree(path);
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
CREATE INDEX group_name_idx ON gms_group USING btree(name);

CREATE TABLE gms_membership (
  group_id varchar NOT NULL,
  user_id varchar NOT NULL,
  primary key (group_id, user_id),
  foreign key (group_id) references gms_group(id)
);

CREATE TYPE permission_type AS ENUM ('VIEW_MEMBERS', 'MANAGE_MEMBERS', 'ADMIN');

CREATE TABLE gms_permission (
  group_id varchar NOT NULL,
  user_id varchar NOT NULL,
  permission permission_type NOT NULL,
28
  group_path ltree NOT NULL, -- group_path is copied here for performance reasons
29
  primary key (group_id, user_id), -- we can have 1 permission for each group
30
31
  foreign key (group_id) references gms_group(id),
  foreign key (group_path) references gms_group(path)
32
);
33
34
35
36
37
38
39

CREATE TABLE gms_client (
  client_id varchar NOT NULL,
  client_secret varchar NOT NULL,
  allowed_actions text[] NOT NULL,
  ip_filter text NULL,
  primary key (client_id)
40
41
42
43
44
45
46
47
48
49
50
51
52
53
);

CREATE TABLE error_log (
  "date" timestamp DEFAULT NOW(),
  "exception_class" varchar,
  "stack_trace" TEXT
);

CREATE TABLE audit_log (
  "date" timestamp DEFAULT NOW(),
  "user" varchar,
  "ip_address" varchar,
  "action" TEXT
);