-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sharinf_db.sql
165 lines (146 loc) · 5.53 KB
/
Sharinf_db.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
-- MySQL Script generated by MySQL Workbench
-- 12/14/15 20:39:50
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `Sharinf_db` DEFAULT CHARACTER SET utf8 ;
USE `Sharinf_db` ;
-- -----------------------------------------------------
-- Table `Sharinf_db`.`Users`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Sharinf_db`.`Users` ;
CREATE TABLE IF NOT EXISTS `Sharinf_db`.`Users` (
`userMail` varchar(50) NOT NULL,
PRIMARY KEY (`userMail`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `Sharinf_db`.`Localization`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Sharinf_db`.`Localization` ;
CREATE TABLE IF NOT EXISTS `Sharinf_db`.`Localization` (
`id` INT NOT NULL AUTO_INCREMENT,
`uuid` varchar(40) NOT NULL,
`major` INT NOT NULL,
`minor` INT NOT NULL,
`lvirtual` INT NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`Directories`
-- -----------------------------------------------------
#DROP TABLE IF EXISTS `Sharinf_db`.`Directories` ;
#CREATE TABLE IF NOT EXISTS `Sharinf_db`.`Directories` (
# `idDirectories` INT NOT NULL AUTO_INCREMENT,
# PRIMARY KEY (`idDirectories`))
#ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`Session`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Sharinf_db`.`Sessions` ;
CREATE TABLE IF NOT EXISTS `Sharinf_db`.`Sessions` (
`idSession` INT NOT NULL AUTO_INCREMENT,
`s_begin` DATETIME NOT NULL,
`s_end` DATETIME NULL,
`activeFlag` BOOLEAN NOT NULL,
`localizationID` INT NOT NULL,
`s_type` INT NOT NULL,
`permissions` INT NOT NULL,
`s_name` VARCHAR(20),
PRIMARY KEY (`idSession`),
INDEX `Localization_idx` (`localizationID` ASC),
CONSTRAINT `localization_ID`
FOREIGN KEY (`localizationID`)
REFERENCES `Sharinf_db`.`Localization` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `Sharinf_db`.`SessionUserList`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Sharinf_db`.`SessionUserList` ;
CREATE TABLE IF NOT EXISTS `Sharinf_db`.`SessionUserList` (
`sessionID` INT NOT NULL,
`user` varchar(50) NOT NULL,
`adminFlag` TINYINT(1) NOT NULL,
INDEX `sessionID_idx` (`sessionID` ASC),
PRIMARY KEY (`sessionID`, `user`),
CONSTRAINT `userMail`
FOREIGN KEY (`user`)
REFERENCES `Sharinf_db`.`Users` (`userMail`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `sessionID`
FOREIGN KEY (`sessionID`)
REFERENCES `Sharinf_db`.`Sessions` (`idSession`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `Sharinf_db`.`Files`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Sharinf_db`.`Files` ;
CREATE TABLE IF NOT EXISTS `Sharinf_db`.`Files` (
`Owner` varchar(50) NOT NULL,
`URL` varchar(150) NOT NULL,
`Name` varchar(150) NOT NULL,
PRIMARY KEY (`URL`),
INDEX `Owner_idx` (`Owner` ASC),
CONSTRAINT `Owner`
FOREIGN KEY (`Owner`)
REFERENCES `Sharinf_db`.`Users` (`userMail`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `Sharinf_db`.`DirectoryFileList`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Sharinf_db`.`SessionFileList` ;
CREATE TABLE IF NOT EXISTS `Sharinf_db`.`SessionFileList` (
`sessionID` INT NOT NULL,
`fileURL` VARCHAR(150) NOT NULL,
PRIMARY KEY (`sessionID`, `fileURL`),
INDEX `fileID_idx` (`fileURL` ASC),
CONSTRAINT `file_URL`
FOREIGN KEY (`fileURL`)
REFERENCES `Sharinf_db`.`Files` (`URL`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `session_ID`
FOREIGN KEY (`sessionID`)
REFERENCES `Sharinf_db`.`Sessions` (`idSession`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `Sharinf_db`.`LocationUserList`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Sharinf_db`.`LocationUserList` ;
CREATE TABLE IF NOT EXISTS `Sharinf_db`.`LocationUserList` (
`userMail` varchar(50) NOT NULL,
`locationId` INT NOT NULL,
PRIMARY KEY (`userMail`, `locationId`),
INDEX `location_idx` (`locationId` ASC),
CONSTRAINT `user`
FOREIGN KEY (`userMail`)
REFERENCES `Sharinf_db`.`Users` (`userMail`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `location`
FOREIGN KEY (`locationId`)
REFERENCES `Sharinf_db`.`Localization` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
DROP VIEW IF EXISTS LocationSession;
CREATE VIEW LocationSession AS SELECT s.idSession AS SessionID, l.id AS localID, s.activeFlag AS Flag FROM Localization l, Sessions s WHERE l.id = s.localizationID;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;