Commit 0f0c1f95 authored by Moreau Elise's avatar Moreau Elise
Browse files

create db migration script

parent ee2bd4d2
...@@ -25,6 +25,9 @@ services: ...@@ -25,6 +25,9 @@ services:
- MYSQL_DATABASE - MYSQL_DATABASE
- MYSQL_USER - MYSQL_USER
- MYSQL_PASSWORD - MYSQL_PASSWORD
volumes:
- ./migrations:/docker-entrypoint-initdb.d
phpmyadmin: phpmyadmin:
image: phpmyadmin image: phpmyadmin
restart: always restart: always
......
CREATE TABLE users (id INT AUTO_INCREMENT NOT NULL, location_id INT DEFAULT NULL, username VARCHAR(255) NOT NULL, firstName VARCHAR(255) NOT NULL, lastName VARCHAR(255) NOT NULL, mail VARCHAR(255) NOT NULL, contaminated TINYINT(1) NOT NULL, password VARCHAR(255) NOT NULL, joinDate DATE NOT NULL, UNIQUE INDEX UNIQ_1483A5E9F85E0677 (username), UNIQUE INDEX UNIQ_1483A5E95126AC48 (mail), UNIQUE INDEX UNIQ_1483A5E964D218E (location_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
CREATE TABLE users_groups (user_id INT NOT NULL, group_id INT NOT NULL, INDEX IDX_FF8AB7E0A76ED395 (user_id), INDEX IDX_FF8AB7E0FE54D947 (group_id), PRIMARY KEY(user_id, group_id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
CREATE TABLE location (id INT AUTO_INCREMENT NOT NULL, latitude DOUBLE PRECISION NOT NULL, longitude DOUBLE PRECISION NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
CREATE TABLE messages (id INT AUTO_INCREMENT NOT NULL, id_receiver INT DEFAULT NULL, id_transmitter INT DEFAULT NULL, date DATETIME NOT NULL, body VARCHAR(255) NOT NULL, INDEX IDX_DB021E966D636003 (id_receiver), INDEX IDX_DB021E96AD47941A (id_transmitter), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
CREATE TABLE groups (id INT AUTO_INCREMENT NOT NULL, admin_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, private INT NOT NULL, UNIQUE INDEX UNIQ_F06D39705E237E06 (name), INDEX IDX_F06D3970642B8210 (admin_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
ALTER TABLE users ADD CONSTRAINT FK_1483A5E964D218E FOREIGN KEY (location_id) REFERENCES location (id);
ALTER TABLE users_groups ADD CONSTRAINT FK_FF8AB7E0A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE;
ALTER TABLE users_groups ADD CONSTRAINT FK_FF8AB7E0FE54D947 FOREIGN KEY (group_id) REFERENCES groups (id) ON DELETE CASCADE;
ALTER TABLE messages ADD CONSTRAINT FK_DB021E966D636003 FOREIGN KEY (id_receiver) REFERENCES groups (id);
ALTER TABLE messages ADD CONSTRAINT FK_DB021E96AD47941A FOREIGN KEY (id_transmitter) REFERENCES users (id);
ALTER TABLE groups ADD CONSTRAINT FK_F06D3970642B8210 FOREIGN KEY (admin_id) REFERENCES users (id);
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment