Sorties de erdiag :
CREATE TABLE Users (
id INTEGER ,
name VARCHAR NOT NULL,
email VARCHAR ,
location VARCHAR ,
birthdate DATE ,
gender CHARACTER ,
avatar TEXT ,
PRIMARY KEY (id)
);
CREATE TABLE Groups (
id INTEGER ,
name VARCHAR NOT NULL,
description TEXT ,
PRIMARY KEY (id)
);
CREATE TABLE Events (
id INTEGER ,
name VARCHAR NOT NULL,
description TEXT ,
PRIMARY KEY (id)
);
CREATE TABLE Messages (
id INTEGER ,
date DATE NOT NULL,
content TEXT NOT NULL,
receiver INTEGER REFERENCES Users(id) NOT NULL,
Users_id INTEGER not null,
PRIMARY KEY (id),
FOREIGN KEY (receiver) REFERENCES Users(id),
FOREIGN KEY (Users_id) REFERENCES Users(id)
);
CREATE TABLE Posts (
id INTEGER ,
content TEXT NOT NULL,
date DATE NOT NULL,
type VARCHAR NOT NULL DEFAULT "Wall",
reference INTEGER NOT NULL,
Users_id INTEGER not null,
PRIMARY KEY (id),
FOREIGN KEY (Users_id) REFERENCES Users(id)
);
CREATE TABLE like (
Users_id INTEGER ,
Posts_id INTEGER ,
PRIMARY KEY (Users_id,Posts_id),
FOREIGN KEY (Users_id) REFERENCES Users(id),
FOREIGN KEY (Posts_id) REFERENCES Posts(id)
);
CREATE TABLE follow (
Users_id INTEGER ,
Users_id2 INTEGER ,
PRIMARY KEY (Users_id,Users_id2),
FOREIGN KEY (Users_id) REFERENCES Users(id),
FOREIGN KEY (Users_id2) REFERENCES Users(id)
);
CREATE TABLE friend_with (
Users_id INTEGER ,
Users_id2 INTEGER ,
PRIMARY KEY (Users_id,Users_id2),
FOREIGN KEY (Users_id) REFERENCES Users(id),
FOREIGN KEY (Users_id2) REFERENCES Users(id)
);
CREATE TABLE participate (
Events_id INTEGER ,
Users_id INTEGER ,
degree VARCHAR NOT NULL DEFAULT "sure",
creator BOOLEAN ,
PRIMARY KEY (Events_id,Users_id),
FOREIGN KEY (Events_id) REFERENCES Events(id),
FOREIGN KEY (Users_id) REFERENCES Users(id)
);
CREATE TABLE belong_to (
Groups_id INTEGER ,
Users_id INTEGER ,
creator BOOLEAN ,
PRIMARY KEY (Groups_id,Users_id),
FOREIGN KEY (Groups_id) REFERENCES Groups(id),
FOREIGN KEY (Users_id) REFERENCES Users(id)
);
Note : 'avatar' est de type 'TEXT' si les images sont stockées encodées
en base 64 par exemple (c'est l'option qu'on choisira).
Une alternative serait d'utiliser le (non)type 'BLOB' pour les stocker directement en binaire.
Entrée de erdiag :
[Users]
+id INTEGER
name VARCHAR NOT NULL
email VARCHAR
location VARCHAR
birthdate DATE
gender CHARACTER
avatar TEXT
[Groups]
+id INTEGER
name VARCHAR NOT NULL
description TEXT
[Events]
+id INTEGER
name VARCHAR NOT NULL
description TEXT
[Messages]
+id INTEGER
date DATE NOT NULL
content TEXT NOT NULL
receiver INTEGER REFERENCES Users(id) NOT NULL
[Posts]
+id INTEGER
content TEXT NOT NULL
date DATE NOT NULL
type VARCHAR NOT NULL DEFAULT "Wall"
reference INTEGER NOT NULL
{publish}
Posts 1
Users *
{send}
Messages 1
Users *
{like}
Users *
Posts *
{follow}
Users *
Users *
{friend_with}
Users *
Users *
{participate}
Events *
Users *
--
degree VARCHAR NOT NULL DEFAULT "sure"
creator BOOLEAN
{belong_to}
Groups +
Users *
--
creator BOOLEAN