Skip to content

Commit 49c5c7c

Browse files
author
hospel
authored
db migration (#106)
1 parent e81f977 commit 49c5c7c

File tree

4 files changed

+20
-61
lines changed

4 files changed

+20
-61
lines changed

.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ COMPOSE_PROJECT_NAME=answer-king-rest-api
22
MYSQLDB_ROOT_PASSWORD=
33
MYSQLDB_DATABASE=answer_king
44
MYSQLDB_USER=test_user
5-
MYSQLDB_PASSWORD=
5+
MYSQLDB_PASSWORD=
6+
MYSQL_URL=jdbc:mysql://mysqldb:3306/answer_king

docker-compose.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ services:
1212
- MYSQL_PASSWORD=$MYSQLDB_PASSWORD
1313
ports:
1414
- "3306:3306"
15+
16+
flyway:
17+
image: flyway/flyway
18+
command: -url=$MYSQL_URL -user=$MYSQLDB_USER -password=$MYSQLDB_PASSWORD -baselineOnMigrate=true -connectRetries=60 migrate
1519
volumes:
16-
- db:/var/lib/mysql
17-
- ./init_scripts/schema.sql:/docker-entrypoint-initdb.d/1.sql
20+
- ./init_scripts:/flyway/sql
21+
depends_on:
22+
- mysqldb
1823

1924
app:
2025
container_name: rest-api
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
CREATE TABLE IF NOT EXISTS category (
2+
id BIGINT NOT NULL AUTO_INCREMENT,
3+
name VARCHAR(255),
4+
description VARCHAR(255) NOT NULL,
5+
createdOn VARCHAR(255) NOT NULL,
6+
lastUpdated VARCHAR(255) NOT NULL,
7+
retired BIT(1) NOT NULL,
8+
9+
PRIMARY KEY (id)
10+
);
11+
112
CREATE TABLE IF NOT EXISTS product (
213
id BIGINT NOT NULL AUTO_INCREMENT,
314
name VARCHAR(255) NOT NULL,
@@ -11,17 +22,6 @@ CREATE TABLE IF NOT EXISTS product (
1122
CONSTRAINT `products_fk_1` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`)
1223
);
1324

14-
CREATE TABLE IF NOT EXISTS category (
15-
id BIGINT NOT NULL AUTO_INCREMENT,
16-
name VARCHAR(255),
17-
description VARCHAR(255) NOT NULL,
18-
createdOn VARCHAR(255) NOT NULL,
19-
lastUpdated VARCHAR(255) NOT NULL,
20-
retired BIT(1) NOT NULL,
21-
22-
PRIMARY KEY (id)
23-
);
24-
2525
CREATE TABLE IF NOT EXISTS product_category (
2626
id BIGINT NOT NULL AUTO_INCREMENT,
2727
product_id BIGINT NOT NULL,

init_scripts/schema.sql

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)