-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.sql
78 lines (66 loc) · 2.54 KB
/
mysql.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
-- MySQL Script generated by MySQL Workbench
-- 04/14/15 00:23:06
-- 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 blackchat
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema blackchat
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `blackchat` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `blackchat` ;
-- -----------------------------------------------------
-- Table `blackchat`.`users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `blackchat`.`users` (
`userID` INT NOT NULL AUTO_INCREMENT,
`login` LONGTEXT NOT NULL,
`psw` LONGTEXT NOT NULL,
UNIQUE INDEX `login_UNIQUE` (`userID` ASC),
PRIMARY KEY (`userID`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `blackchat`.`dialogs`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `blackchat`.`dialogs` (
`dialogID` INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`dialogID`),
UNIQUE INDEX `dialogID_UNIQUE` (`dialogID` ASC))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `blackchat`.`users_dialogs`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `blackchat`.`users_dialogs` (
`userID` INT NOT NULL,
`dialogID` INT NOT NULL,
PRIMARY KEY (`userID`, `dialogID`),
INDEX `dialog_idx` (`dialogID` ASC),
CONSTRAINT `user`
FOREIGN KEY (`userID`)
REFERENCES `blackchat`.`users` (`userID`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `dialog`
FOREIGN KEY (`dialogID`)
REFERENCES `blackchat`.`dialogs` (`dialogID`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `blackchat`.`mails`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `blackchat`.`mails` (
`dialogID` INT NOT NULL,
`mailID` INT NOT NULL AUTO_INCREMENT,
`userID` INT NOT NULL,
`text` LONGTEXT NOT NULL,
PRIMARY KEY (`dialogID`, `mailID`),
INDEX `userID_idx` (`userID` ASC))
ENGINE = MyISAM;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;