11
22-- Drop Tables
33
4- DROP TABLE IF EXISTS groups_accounts;
5- DROP TABLE IF EXISTS groups;
4+
65DROP TABLE IF EXISTS organization_person;
76DROP TABLE IF EXISTS organization;
87DROP TABLE IF EXISTS login_history;
98DROP TABLE IF EXISTS login_details;
109DROP TABLE IF EXISTS person_role;
1110DROP TABLE IF EXISTS person;
11+ DROP TABLE IF EXISTS composed_roles;
1212DROP TABLE IF EXISTS role;
1313DROP TABLE IF EXISTS account;
1414DROP TABLE IF EXISTS contact;
@@ -32,6 +32,11 @@ CREATE TABLE account
3232);
3333
3434
35+ CREATE TABLE composed_roles
36+ (
37+ ROLE_ID bigint (10 ) unsigned NOT NULL ,
38+ COMPOSED_ROLE_ID bigint (10 ) unsigned NOT NULL
39+ );
3540CREATE TABLE contact
3641(
3742 ID bigint (10 ) unsigned NOT NULL AUTO_INCREMENT,
@@ -41,23 +46,6 @@ Application modules can decide on the schema of this json object',
4146);
4247
4348
44- CREATE TABLE groups
45- (
46- ID bigint (10 ) unsigned NOT NULL AUTO_INCREMENT,
47- ACCOUNT_ID bigint (10 ) unsigned NOT NULL ,
48- NAME varchar (20 ),
49- PRIMARY KEY (ID),
50- UNIQUE (ACCOUNT_ID)
51- );
52-
53-
54- CREATE TABLE groups_accounts
55- (
56- GROUP_ID bigint (10 ) unsigned NOT NULL ,
57- ACCOUNT_ID bigint (10 ) unsigned NOT NULL ,
58- ACCOUNT_TYPE enum(' ORGANIZATION' ,' PERSON' ,' GROUPS' ,' ROLE' ) NOT NULL ,
59- UNIQUE (GROUP_ID, ACCOUNT_ID)
60- );
6149
6250
6351CREATE TABLE login_details
@@ -101,6 +89,7 @@ CREATE TABLE organization_person
10189(
10290 ORGANIZATION_ID bigint (10 ) unsigned NOT NULL ,
10391 PERSON_ID bigint (10 ) unsigned NOT NULL ,
92+ TYPE enum(' OWNER' ,' ADMINISTRATOR' ,' MEMBER' ) DEFAULT ' MEMBER' NOT NULL ,
10493 UNIQUE (ORGANIZATION_ID, PERSON_ID)
10594);
10695
@@ -155,27 +144,6 @@ ALTER TABLE account
155144 ON DELETE SET NULL
156145;
157146
158- ALTER TABLE groups
159- ADD FOREIGN KEY (ACCOUNT_ID)
160- REFERENCES account (ID)
161- ON UPDATE CASCADE
162- ON DELETE RESTRICT
163- ;
164-
165- ALTER TABLE groups_accounts
166- ADD FOREIGN KEY (ACCOUNT_ID)
167- REFERENCES account (ID)
168- ON UPDATE CASCADE
169- ON DELETE CASCADE
170- ;
171-
172- ALTER TABLE groups_accounts
173- ADD FOREIGN KEY (GROUP_ID)
174- REFERENCES groups (ID)
175- ON UPDATE CASCADE
176- ON DELETE RESTRICT
177- ;
178-
179147ALTER TABLE organization
180148 ADD FOREIGN KEY (ACCOUNT_ID)
181149 REFERENCES account (ID)
@@ -244,6 +212,20 @@ ALTER TABLE person_role
244212 ON DELETE CASCADE
245213;
246214
215+ ALTER TABLE composed_roles
216+ ADD FOREIGN KEY (ROLE_ID)
217+ REFERENCES ROLE (ID)
218+ ON UPDATE RESTRICT
219+ ON DELETE RESTRICT
220+ ;
221+
222+
223+ ALTER TABLE composed_roles
224+ ADD FOREIGN KEY (COMPOSED_ROLE_ID)
225+ REFERENCES ROLE (ID)
226+ ON UPDATE CASCADE
227+ ON DELETE CASCADE
228+ ;
247229ALTER TABLE person_role
248230 ADD FOREIGN KEY (ROLE_ID)
249231 REFERENCES role (ID)
0 commit comments