Skip to content

Commit

Permalink
Declares a relational database service. Refs #3
Browse files Browse the repository at this point in the history
  • Loading branch information
ariel17 committed Mar 7, 2023
1 parent 74c4d7f commit 6216b58
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
services:
api:
build: .
ports:
- "8080:8080"
depends_on:
- db

db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: challenge
MYSQL_DATABASE: challenge
ports:
- "3306:3306"
volumes:
- "./init.sql:/docker-entrypoint-initdb.d/1.sql"
44 changes: 44 additions & 0 deletions init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
CREATE DATABASE `challenge`;
USE `challenge`;

CREATE TABLE `persons` (
`id` INT unsigned,
`name` VARCHAR(50),
`date_of_birth` CHAR(10),
`nationality` VARCHAR(20),
PRIMARY KEY (`id`)
);

CREATE TABLE `teams` (
`tla` CHAR(3),
`name` VARCHAR(50),
`short_name` VARCHAR(100),
`area_name` VARCHAR(50),
`address` VARCHAR(200),
PRIMARY KEY (`tla`)
);

CREATE TABLE `teams_persons` (
`team_tla` CHAR(3),
`person_id` INT unsigned,
`position` VARCHAR(20),
CONSTRAINT uc_person_by_team UNIQUE (`team_tla`, `person_id`),
FOREIGN KEY (`team_tla`) REFERENCES teams (`tla`),
FOREIGN KEY (`person_id`) REFERENCES persons (`id`)
);

CREATE TABLE `competitions` (
`code` CHAR(4),
`name` VARCHAR(50),
`area_name` VARCHAR(50),
`address` VARCHAR(200),
PRIMARY KEY (`code`)
);

CREATE TABLE `competitions_teams` (
`code` CHAR(4),
`team_tla` CHAR(3),
CONSTRAINT uc_team_by_competition UNIQUE (`code`, `team_tla`),
FOREIGN KEY (`code`) REFERENCES competitions (`code`),
FOREIGN KEY (`team_tla`) REFERENCES teams (`tla`)
);

0 comments on commit 6216b58

Please sign in to comment.