Salome HOME
File service
[modules/gde.git] / projects / GDE_App / src / GDE_DB_Init.sql
1 /* Unique Ids sequence generator */
2
3 drop sequence if exists SEQ_GEN_SEQUENCE;
4 create sequence SEQ_GEN_SEQUENCE START WITH 1000 INCREMENT BY 50;
5
6
7 DROP TABLE IF EXISTS GROUP_ CASCADE;
8 CREATE TABLE GROUP_ (
9     id bigint NOT NULL PRIMARY KEY,
10     groupName varchar(255) NOT NULL
11 );
12
13 DROP TABLE IF EXISTS USERS CASCADE;
14 CREATE TABLE USERS (
15     id bigint NOT NULL PRIMARY KEY,
16     userName varchar(255) not null,
17     userpassword varchar(255) not null
18 );
19 CREATE INDEX users_username_index ON USERS(userName);
20
21 DROP TABLE IF EXISTS USERGROUP CASCADE;
22 CREATE TABLE USERGROUP (
23     id bigint NOT NULL PRIMARY KEY,
24     groupId bigint references GROUP_(id) on delete cascade,
25     userId bigint references USERS(id)  on delete cascade
26 );
27 create index usergroup_groupId_idx ON USERGROUP(groupId);
28
29 DROP TABLE IF EXISTS GROUPPERMISSIONS CASCADE;
30 CREATE TABLE GROUPPERMISSIONS (
31     id bigint NOT NULL PRIMARY KEY,
32     groupId bigint references GROUP_(id),
33     serviceName varchar(255) not null,
34     methodIndex int not null
35 );
36
37 /* METADATA */
38
39 DROP TABLE IF EXISTS attribute_group CASCADE;
40 CREATE TABLE attribute_group (
41     id bigint NOT NULL PRIMARY KEY
42 );
43
44 DROP TABLE IF EXISTS attribute CASCADE;
45 CREATE TABLE attribute (
46     id bigint NOT NULL PRIMARY KEY,
47     name varchar(255),
48     type varchar(255),
49     value varchar(255),
50     attribute_group_id bigint not null REFERENCES attribute_group (id)  on delete cascade on update cascade,
51     mandatory boolean
52 );
53
54 /* PROFILE */
55
56 DROP TABLE IF EXISTS profile CASCADE;
57 CREATE TABLE profile (
58     id bigint NOT NULL PRIMARY KEY,
59     name varchar(255)
60 );
61
62 DROP TABLE IF EXISTS profile_attribute CASCADE;
63 CREATE TABLE profile_attribute (
64     id bigint NOT NULL PRIMARY KEY,
65     name varchar(255),
66     type varchar(255),
67     mandatory boolean,
68     profile_id bigint not null REFERENCES profile (id) on delete cascade on update cascade
69 );
70
71 /* DATA */
72 DROP TABLE IF EXISTS gde_file CASCADE;
73 CREATE TABLE gde_file (
74     id bigint NOT NULL PRIMARY KEY,
75     name varchar(255),
76     length bigint,
77     checksum varchar(255),
78     creation_date timestamp,
79     update_date timestamp,
80     valid boolean,
81     deleted boolean,
82     deletion_date timestamp,
83     attribute_group_id bigint REFERENCES attribute_group (id),
84     data_profile_id bigint REFERENCES profile (id)
85 );
86
87 DROP TABLE IF EXISTS chunk CASCADE;
88 CREATE TABLE chunk (
89     id bigint NOT NULL PRIMARY KEY,
90     file_id bigint NOT NULL REFERENCES gde_file (id),
91     rank bigint,
92     checksum varchar(255),
93     size bigint,
94     data bytea
95 );
96
97 /* STUDIES */
98 DROP TABLE IF EXISTS study CASCADE;
99 CREATE TABLE study (
100     id bigint NOT NULL PRIMARY KEY,
101     name varchar(255),
102     creation_date timestamp,
103     update_date timestamp,
104     valid boolean,
105     deleted boolean,
106     deletion_date timestamp,
107     attribute_group_id bigint REFERENCES attribute_group (id),
108     profile_id bigint REFERENCES profile (id),
109     locked boolean,
110     lock_owner bigint references users(id)
111 );
112 /* PROFILES */
113
114
115 -- The 1000 first ids are reserved for initial data
116 INSERT INTO users (id,username,userpassword) VALUES (1,'admin','edf123');
117 INSERT INTO group_ (id,groupname) VALUES (1,'admins');
118 INSERT into usergroup(id,groupid,userid) VALUES (2,1,1);
119 /* User management permissions */
120 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (3, 1, 'UserService',1); -- Create user 
121 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (4, 1, 'UserService',2); -- Delete user
122 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (5, 1, 'UserService',3); -- Add to group
123 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (6, 1, 'UserService',4); -- Remove from group
124 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (7, 1, 'UserService',5); -- Create group
125 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (8, 1, 'UserService',6); -- Delete group
126 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (9, 1, 'UserService',7); -- Find user
127 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (10, 1, 'UserService',8); -- Find group
128 /* Studies permissions */
129 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (11, 1, 'StudyService',1); -- Create study
130 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (12, 1, 'StudyService',2); -- Set study state
131 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (13, 1, 'StudyService',3); -- Read study
132 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (14, 1, 'StudyService',4); -- Delete study
133 /* Profiles services */
134 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (15, 1, 'ProfilesService',1); -- Create profile
135 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (16, 1, 'ProfilesService',2); -- Delete profile
136 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (17, 1, 'ProfilesService',3); -- Read profile
137 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (18, 1, 'ProfilesService',4); -- Update profile
138 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (19, 1, 'ProfilesService',5); -- Create profile attribute
139 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (20, 1, 'ProfilesService',6); -- Delete profile attribute
140 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (21, 1, 'ProfilesService',7); -- Read profile attribute
141 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (22, 1, 'ProfilesService',8); -- Update profile attribute
142 /* Attributes services */
143 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (23, 1, 'AttributesService',1); -- Create attribute
144 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (24, 1, 'AttributesService',2); -- Delete attribute
145 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (25, 1, 'AttributesService',3); -- Read attribute
146 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (26, 1, 'AttributesService',4); -- Create attribute group
147 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (27, 1, 'AttributesService',5); -- Delete attribute group
148 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (28, 1, 'AttributesService',6); -- Update attribute group
149 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (29, 1, 'AttributesService',7); -- Read attribute group
150 /* File services */ 
151 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (30, 1, 'FileService',1); -- 
152 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (31, 1, 'FileService',2); -- 
153 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (32, 1, 'FileService',3); -- 
154 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (33, 1, 'FileService',4); -- 
155 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (34, 1, 'FileService',5); -- 
156 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (35, 1, 'FileService',6); -- 
157 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (36, 1, 'FileService',7); --