-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcodechatDatabase.sql
143 lines (128 loc) · 3.92 KB
/
codechatDatabase.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
CREATE TABLE user(
id INT AUTO_INCREMENT PRIMARY KEY,
pseudo VARCHAR(50) NOT NULL,
mail VARCHAR(50) NOT NULL,
lastName VARCHAR(50),
firstName VARCHAR(50),
grade INT2 NOT NULL DEFAULT 0,
subscription INT2 NOT NULL DEFAULT 0,
postalCode CHAR(5),
city VARCHAR(50),
address VARCHAR(50),
password VARCHAR(255),
banned boolean NOT NULL DEFAULT 0,
admin boolean NOT NULL DEFAULT 0,
wantNews boolean NOT NULL DEFAULT 1,
creation DATETIME NOT NULL DEFAULT NOW(),
lastLogin DATETIME NOT NULL DEFAULT NOW(),
verif BOOLEAN NOT NULL DEFAULT 0
);
CREATE TABLE publication(
id INT AUTO_INCREMENT PRIMARY KEY,
content TEXT,
lastEdition DATETIME NOT NULL DEFAULT NOW(),
respondTo INT,
creator INT NOT NULL,
FOREIGN KEY(respondTo) REFERENCES publication(id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(creator) REFERENCES user(id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE image(
id INT AUTO_INCREMENT PRIMARY KEY,
path VARCHAR(255) NOT NULL,
publication INT NOT NULL,
FOREIGN KEY (publication) REFERENCES publication(id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE liked(
publication INT,
user INT,
PRIMARY KEY (publication, user),
FOREIGN KEY (user) REFERENCES user(id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (publication) REFERENCES publication(id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE follow(
follower INT,
followed INT,
PRIMARY KEY (followed, follower),
FOREIGN KEY(follower) REFERENCES user(id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(followed) REFERENCES user(id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE avatarcomponent(
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
path VARCHAR(50) NOT NULL,
type INT
);
CREATE TABLE avatarownership(
owner INT,
component INT,
PRIMARY KEY(owner, component),
FOREIGN KEY(owner) REFERENCES user(id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(component) REFERENCES avatarcomponent(id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE events (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
description VARCHAR(255),
starting_date DATETIME,
ending_date DATETIME,
location VARCHAR(100),
user INT,
max_signups INT,
FOREIGN KEY (user) REFERENCES user(id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE eventSign (
signer VARCHAR(80) REFERENCES user(id) ON DELETE CASCADE ON UPDATE CASCADE,
event VARCHAR(80) REFERENCES events(id) ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY (signer, event)
);
CREATE TABLE message(
id INT AUTO_INCREMENT PRIMARY KEY,
author INT REFERENCES user(id),
receiver INT REFERENCES user(id),
content VARCHAR(255) NOT NULL,
creation DATETIME NOT NULL DEFAULT NOW()
);
CREATE TABLE token(
token CHAR(32) PRIMARY KEY,
creation DATETIME DEFAULT NOW() NOT NULL,
owner INT NOT NULL UNIQUE REFERENCES user(id)
);
CREATE TABLE newsletter (
id int(11) PRIMARY KEY NOT NULL AUTO_INCREMENT,
title TEXT,
content TEXT,
creationDateTime DATETIME,
sendDateTime DATETIME,
deleted BOOLEAN DEFAULT 0,
createBy VARCHAR(50),
sent BOOLEAN DEFAULT 0,
sendTo VARCHAR(18)
);
CREATE TABLE sendTo (
id_newsletter INT,
id_user INT,
PRIMARY KEY (id_newsletter, id_user),
FOREIGN KEY(id_newsletter) REFERENCES newsletter(id),
FOREIGN KEY(id_user) REFERENCES user(id)
);
CREATE TABLE send (
id INT PRIMARY KEY,
month INT,
day INT,
hour INT,
minute INT,
date DATE,
lastSendDate DATE,
lastSendTime TIME,
lastUpdate DATETIME
);
CREATE TABLE request (
id INT PRIMARY KEY,
id_user INT,
title VARCHAR(100),
content TEXT,
urgence_level INT,
date DATETIME,
close BOOLEAN DEFAULT 0
);
ALTER TABLE user ADD verif BOOLEAN NOT NULL DEFAULT 0;