Salome HOME
5e2992d68cb5ab75c437ea4f745d9008aa898e36
[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 /* DATA */
55
56 DROP TABLE IF EXISTS gde_file CASCADE;
57 CREATE TABLE gde_file (
58     id bigint NOT NULL PRIMARY KEY,
59     name varchar(255),
60     length bigint,
61     checksum varchar(255),
62     creation_date timestamp,
63     update_date timestamp,
64     valid boolean,
65     deleted boolean,
66     deletion_date timestamp,
67     attribute_group_id bigint REFERENCES attribute_group (id),
68     data_profile_id bigint REFERENCES profile (id)
69 );
70
71 DROP TABLE IF EXISTS chunk CASCADE;
72 CREATE TABLE chunk (
73     id bigint NOT NULL PRIMARY KEY,
74     file_id bigint NOT NULL REFERENCES gde_file (id),
75     rank bigint,
76     checksum varchar(255),
77     size bigint,
78     data bytea
79 );
80
81 /* STUDIES */
82
83 DROP TABLE IF EXISTS study CASCADE;
84 CREATE TABLE study (
85     id bigint NOT NULL PRIMARY KEY,
86     name 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     profile_id bigint REFERENCES profile (id)
94 );
95
96 /* PROFILES */
97
98 DROP TABLE IF EXISTS profile CASCADE;
99 CREATE TABLE profile (
100     id bigint NOT NULL PRIMARY KEY,
101     name varchar(255)
102 );
103
104 DROP TABLE IF EXISTS profile_attribute CASCADE;
105 CREATE TABLE profile_attribute (
106     id bigint NOT NULL PRIMARY KEY,
107     name varchar(255),
108     type varchar(255),
109     mandatory boolean,
110     profile_id bigint REFERENCES profile (id)
111 );
112
113 -- The 1000 first ids are reserved for initial data
114 INSERT INTO users (id,username,userpassword) VALUES (1,'admin','edf123');
115 INSERT INTO group_ (id,groupname) VALUES (1,'admins');
116 INSERT into usergroup(id,groupid,userid) VALUES (2,1,1);
117 INSERT INTO grouppermissions (id,groupid,servicename,methodname) VALUES (3, 1, 'UserService','CREATEUSER');