Salome HOME
Merge with master
[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 INCREMENT BY 50;
5
6
7 DROP TABLE IF EXISTS GROUP_;
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;
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;
22 CREATE TABLE USERGROUP (
23     id bigint NOT NULL PRIMARY KEY,
24     groupId bigint references GROUP_(id),
25     userId bigint references USERS(id)
26 );
27
28 DROP TABLE IF EXISTS USERPERMISSIONS;
29 CREATE TABLE USERPERMISSIONS (
30     id bigint NOT NULL PRIMARY KEY,
31     groupId bigint references GROUP_(id),
32     serviceName varchar(255) not null,
33     methodName varchar(255) not null
34 );
35
36 /* METADATA */
37
38 DROP TABLE IF EXISTS attribute_group CASCADE;
39 CREATE TABLE attribute_group (
40     id bigint NOT NULL PRIMARY KEY
41 );
42
43 DROP TABLE IF EXISTS attribute CASCADE;
44 CREATE TABLE attribute (
45     id bigint NOT NULL PRIMARY KEY,
46     name varchar(255),
47     type varchar(255),
48     value varchar(255),
49     attribute_group_id bigint REFERENCES attribute_group (id),
50     mandatory boolean
51 );
52
53 /* DATA */
54
55 DROP TABLE IF EXISTS gde_file CASCADE;
56 CREATE TABLE gde_file (
57     id bigint NOT NULL PRIMARY KEY,
58     name varchar(255),
59     length bigint,
60     checksum varchar(255),
61     creation_date timestamp,
62     update_date timestamp,
63     valid boolean,
64     deleted boolean,
65     deletion_date timestamp,
66     attribute_group_id bigint REFERENCES attribute_group (id),
67     data_profile_id bigint REFERENCES profile (id)
68 );
69
70 DROP TABLE IF EXISTS chunk CASCADE;
71 CREATE TABLE chunk (
72     id bigint NOT NULL PRIMARY KEY,
73     file_id bigint NOT NULL REFERENCES gde_file (id),
74     rank bigint,
75     checksum varchar(255),
76     size bigint,
77     data bytea
78 );
79
80 /* STUDIES */
81
82 DROP TABLE IF EXISTS study CASCADE;
83 CREATE TABLE study (
84     id bigint NOT NULL PRIMARY KEY,
85     name varchar(255),
86     creation_date timestamp,
87     update_date timestamp,
88     valid boolean,
89     deleted boolean,
90     deletion_date timestamp,
91     attribute_group_id bigint REFERENCES attribute_group (id),
92     profile_id bigint REFERENCES profile (id)
93 );
94
95 /* PROFILES */
96
97 DROP TABLE IF EXISTS profile CASCADE;
98 CREATE TABLE profile (
99     id bigint NOT NULL PRIMARY KEY,
100     name varchar(255)
101 );
102
103 DROP TABLE IF EXISTS profile_attribute CASCADE;
104 CREATE TABLE profile_attribute (
105     id bigint NOT NULL PRIMARY KEY,
106     name varchar(255),
107     type varchar(255),
108     mandatory boolean,
109     profile_id bigint REFERENCES profile (id)
110 );