-
Notifications
You must be signed in to change notification settings - Fork 2
/
Niveau2.sql
141 lines (125 loc) · 4.82 KB
/
Niveau2.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
-- MySQL Script generated by MySQL Workbench
-- dim. 06 déc. 2020 10:10:47
-- 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 socialnetwork
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema socialnetwork
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `socialnetwork` ;
USE `socialnetwork` ;
-- -----------------------------------------------------
-- Table `socialnetwork`.`users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `socialnetwork`.`users` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`email` VARCHAR(255) NOT NULL,
`password` VARCHAR(255) NOT NULL,
`alias` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `email_UNIQUE` (`email` ASC),
UNIQUE INDEX `alias_UNIQUE` (`alias` ASC))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `socialnetwork`.`posts`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `socialnetwork`.`posts` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`user_id` INT UNSIGNED NOT NULL,
`content` TEXT NOT NULL,
`created` DATETIME NOT NULL,
`parent_id` INT UNSIGNED NULL,
PRIMARY KEY (`id`),
INDEX `fk_posts_users_idx` (`user_id` ASC),
INDEX `fk_posts_posts1_idx` (`parent_id` ASC),
CONSTRAINT `fk_posts_users`
FOREIGN KEY (`user_id`)
REFERENCES `socialnetwork`.`users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_posts_posts1`
FOREIGN KEY (`parent_id`)
REFERENCES `socialnetwork`.`posts` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `socialnetwork`.`tags`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `socialnetwork`.`tags` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`label` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `label_UNIQUE` (`label` ASC))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `socialnetwork`.`posts_tags`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `socialnetwork`.`posts_tags` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`post_id` INT UNSIGNED NOT NULL,
`tag_id` INT UNSIGNED NOT NULL,
INDEX `fk_posts_has_tags_tags1_idx` (`tag_id` ASC),
INDEX `fk_posts_has_tags_posts1_idx` (`post_id` ASC),
PRIMARY KEY (`id`),
CONSTRAINT `fk_posts_has_tags_posts1`
FOREIGN KEY (`post_id`)
REFERENCES `socialnetwork`.`posts` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_posts_has_tags_tags1`
FOREIGN KEY (`tag_id`)
REFERENCES `socialnetwork`.`tags` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `socialnetwork`.`followers`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `socialnetwork`.`followers` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`followed_user_id` INT UNSIGNED NOT NULL,
`following_user_id` INT UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_users_has_users_users2_idx` (`following_user_id` ASC),
INDEX `fk_users_has_users_users1_idx` (`followed_user_id` ASC),
CONSTRAINT `fk_users_has_users_users1`
FOREIGN KEY (`followed_user_id`)
REFERENCES `socialnetwork`.`users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_users_has_users_users2`
FOREIGN KEY (`following_user_id`)
REFERENCES `socialnetwork`.`users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `socialnetwork`.`likes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `socialnetwork`.`likes` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`user_id` INT UNSIGNED NOT NULL,
`post_id` INT UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_users_has_posts_posts1_idx` (`post_id` ASC),
INDEX `fk_users_has_posts_users1_idx` (`user_id` ASC),
CONSTRAINT `fk_users_has_posts_users1`
FOREIGN KEY (`user_id`)
REFERENCES `socialnetwork`.`users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_users_has_posts_posts1`
FOREIGN KEY (`post_id`)
REFERENCES `socialnetwork`.`posts` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;