generated from ariel17/golang-base
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Declares a relational database service. Refs #3
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`) | ||
); |