Salome HOME
Attribute DAO
[modules/gde.git] / projects / GDE_App / src / GDE_DB_Init.sql
1 /* Unique Ids sequence generator */
2
3 drop sequence 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 REFERENCES attribute_group (id),
51     mandatory boolean
52 );
53
54 DROP TABLE IF EXISTS attribute_group_attribute CASCADE;
55 CREATE TABLE attribute_group_attribute (
56     attributegroup_id bigint REFERENCES attribute_group (id),
57     attribute_id bigint REFERENCES attribute(id)
58 );
59 CREATE INDEX attribute_group_attribute_idx1 on attribute_group_attribute(attributegroup_id);
60 CREATE INDEX attribute_group_attribute_idx2 on attribute_group_attribute(attribute_id);
61
62 /* DATA */
63
64 DROP TABLE IF EXISTS gde_file CASCADE;
65 CREATE TABLE gde_file (
66     id bigint NOT NULL PRIMARY KEY,
67     name varchar(255),
68     length bigint,
69     checksum varchar(255),
70     creation_date timestamp,
71     update_date timestamp,
72     valid boolean,
73     deleted boolean,
74     deletion_date timestamp,
75     attribute_group_id bigint REFERENCES attribute_group (id),
76     data_profile_id bigint REFERENCES profile (id)
77 );
78
79 DROP TABLE IF EXISTS chunk CASCADE;
80 CREATE TABLE chunk (
81     id bigint NOT NULL PRIMARY KEY,
82     file_id bigint NOT NULL REFERENCES gde_file (id),
83     rank bigint,
84     checksum varchar(255),
85     size bigint,
86     data bytea
87 );
88
89 /* STUDIES */
90
91 DROP TABLE IF EXISTS study CASCADE;
92 CREATE TABLE study (
93     id bigint NOT NULL PRIMARY KEY,
94     name varchar(255),
95     creation_date timestamp,
96     update_date timestamp,
97     valid boolean,
98     deleted boolean,
99     deletion_date timestamp,
100     attribute_group_id bigint REFERENCES attribute_group (id),
101     profile_id bigint REFERENCES profile (id),
102     locked boolean
103 );
104 /* PROFILES */
105
106 DROP TABLE IF EXISTS profile CASCADE;
107 CREATE TABLE profile (
108     id bigint NOT NULL PRIMARY KEY,
109     name varchar(255)
110 );
111
112 DROP TABLE IF EXISTS profile_attribute CASCADE;
113 CREATE TABLE profile_attribute (
114     id bigint NOT NULL PRIMARY KEY,
115     name varchar(255),
116     type varchar(255),
117     mandatory boolean,
118     profile_id bigint REFERENCES profile (id)
119 );
120
121 -- The 1000 first ids are reserved for initial data
122 INSERT INTO users (id,username,userpassword) VALUES (1,'admin','edf123');
123 INSERT INTO group_ (id,groupname) VALUES (1,'admins');
124 INSERT into usergroup(id,groupid,userid) VALUES (2,1,1);
125 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (3, 1, 'UserService',1); -- Create user 
126 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (4, 1, 'UserService',2); -- Delete user
127 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (5, 1, 'UserService',3); -- Add to group
128 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (6, 1, 'UserService',4); -- Remove from group
129 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (7, 1, 'UserService',5); -- Create group
130 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (8, 1, 'UserService',6); -- Delete group
131 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (9, 1, 'UserService',7); -- Find user
132 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (10, 1, 'UserService',8); -- Find group
133
134