Salome HOME
Remove unused indexes
[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
30
31 DROP TABLE IF EXISTS GROUPPERMISSIONS CASCADE;
32 CREATE TABLE GROUPPERMISSIONS (
33     id bigint NOT NULL PRIMARY KEY,
34     groupId bigint references GROUP_(id),
35     serviceName varchar(255) not null,
36     methodIndex int not null
37 );
38
39 /* METADATA */
40
41 DROP TABLE IF EXISTS attribute_group CASCADE;
42 CREATE TABLE attribute_group (
43     id bigint NOT NULL PRIMARY KEY
44 );
45
46 DROP TABLE IF EXISTS attribute CASCADE;
47 CREATE TABLE attribute (
48     id bigint NOT NULL PRIMARY KEY,
49     name varchar(255),
50     type varchar(255),
51     value varchar(255),
52     attribute_group_id bigint REFERENCES attribute_group (id),
53     mandatory boolean
54 );
55
56 DROP TABLE IF EXISTS attribute_group_attribute CASCADE;
57 CREATE TABLE attribute_group_attribute
58 (
59   attributegroup_id bigint  REFERENCES attribute_group (id) ON UPDATE NO ACTION ON DELETE NO ACTION,
60   attribute_id bigint REFERENCES attribute (id) ON UPDATE NO ACTION ON DELETE NO ACTION
61 );
62 alter table attribute_group_attribute add primary key (attributegroup_id, attribute_id);
63
64 DROP TABLE IF EXISTS profile CASCADE;
65 CREATE TABLE profile (
66     id bigint NOT NULL PRIMARY KEY,
67     name varchar(255)
68 );
69
70 DROP TABLE IF EXISTS profile_attribute CASCADE;
71 CREATE TABLE profile_attribute (
72     id bigint NOT NULL PRIMARY KEY,
73     name varchar(255),
74     type varchar(255),
75     mandatory boolean,
76     profile_id bigint REFERENCES profile (id)
77 );
78
79 /* DATA */
80
81 DROP TABLE IF EXISTS gde_file CASCADE;
82 CREATE TABLE gde_file (
83     id bigint NOT NULL PRIMARY KEY,
84     name varchar(255),
85     length bigint,
86     checksum varchar(255),
87     creation_date timestamp,
88     update_date timestamp,
89     valid boolean,
90     deleted boolean,
91     deletion_date timestamp,
92     attribute_group_id bigint REFERENCES attribute_group (id),
93     data_profile_id bigint REFERENCES profile (id)
94 );
95
96 DROP TABLE IF EXISTS chunk CASCADE;
97 CREATE TABLE chunk (
98     id bigint NOT NULL PRIMARY KEY,
99     file_id bigint NOT NULL REFERENCES gde_file (id),
100     rank bigint,
101     checksum varchar(255),
102     size bigint,
103     data bytea
104 );
105
106 /* STUDIES */
107
108 DROP TABLE IF EXISTS study CASCADE;
109 CREATE TABLE study (
110     id bigint NOT NULL PRIMARY KEY,
111     name varchar(255),
112     creation_date timestamp,
113     update_date timestamp,
114     valid boolean,
115     deleted boolean,
116     deletion_date timestamp,
117     attribute_group_id bigint REFERENCES attribute_group (id),
118     profile_id bigint REFERENCES profile (id),
119     locked boolean
120 );
121 /* PROFILES */
122
123
124 -- The 1000 first ids are reserved for initial data
125 INSERT INTO users (id,username,userpassword) VALUES (1,'admin','edf123');
126 INSERT INTO group_ (id,groupname) VALUES (1,'admins');
127 INSERT into usergroup(id,groupid,userid) VALUES (2,1,1);
128 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (3, 1, 'UserService',1); -- Create user 
129 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (4, 1, 'UserService',2); -- Delete user
130 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (5, 1, 'UserService',3); -- Add to group
131 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (6, 1, 'UserService',4); -- Remove from group
132 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (7, 1, 'UserService',5); -- Create group
133 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (8, 1, 'UserService',6); -- Delete group
134 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (9, 1, 'UserService',7); -- Find user
135 INSERT INTO GROUPPERMISSIONS (id,groupid,servicename,methodindex) VALUES (10, 1, 'UserService',8); -- Find group
136
137