Skip to content

Commit c185f58

Browse files
feat: add Flyway migrations (#94)
1 parent c051437 commit c185f58

File tree

8 files changed

+89
-4
lines changed

8 files changed

+89
-4
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,7 @@ buildNumber.properties
193193
# End of https://www.gitignore.io/api/java,maven,eclipse,intellij+all
194194

195195
### Derby ###
196-
197196
campsitedb/
197+
198+
### IntelliJ/JPA Buddy plugin ###
199+
.jpb/

pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
3838
<java.version>17</java.version>
3939
<testcontainers.version>1.19.1</testcontainers.version>
40+
<flyway.core.version>9.22.3</flyway.core.version>
4041
<!-- Sonar Cloud -->
4142
<sonar.organization>igor-baiborodine-github</sonar.organization>
4243
<sonar.projectKey>igor-baiborodine_campsite-booking</sonar.projectKey>
@@ -150,6 +151,16 @@
150151
<version>1.5.3.Final</version>
151152
<optional>true</optional>
152153
</dependency>
154+
<dependency>
155+
<groupId>org.flywaydb</groupId>
156+
<artifactId>flyway-core</artifactId>
157+
<version>${flyway.core.version}</version>
158+
</dependency>
159+
<dependency>
160+
<groupId>org.flywaydb</groupId>
161+
<artifactId>flyway-mysql</artifactId>
162+
<version>${flyway.core.version}</version>
163+
</dependency>
153164
<!--TESTS-->
154165
<dependency>
155166
<groupId>org.jeasy</groupId>
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# Apache Derby
22
spring.datasource.url=jdbc:derby:campsitedb;create=true
3-
spring.jpa.hibernate.ddl-auto=create
43
spring.jpa.properties.hibernate.show_sql=true

src/main/resources/application.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ spring.applicaiton.name=campsite-booking-api
22

33
server.port=8080
44

5-
spring.jpa.hibernate.ddl-auto=update
65
spring.jpa.properties.hibernate.show_sql=false
76
spring.jpa.properties.hibernate.use_sql_comments=true
8-
spring.jpa.properties.hibernate.format_sql=
7+
spring.jpa.properties.hibernate.format_sql=false
8+
9+
spring.flyway.locations=classpath:db/migration/{vendor}
910

1011
query.findForDateRangeWithPessimisticWriteLockingLockTimeoutInMs=3000
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CREATE TABLE campsites
2+
(
3+
id BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY,
4+
capacity INT NOT NULL,
5+
restrooms BOOLEAN NOT NULL,
6+
drinking_water BOOLEAN NOT NULL,
7+
picnic_table BOOLEAN NOT NULL,
8+
fire_pit BOOLEAN NOT NULL,
9+
active BOOLEAN NOT NULL,
10+
created_at TIMESTAMP NOT NULL,
11+
updated_at TIMESTAMP NOT NULL,
12+
CONSTRAINT pk_campsites PRIMARY KEY (id)
13+
);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
CREATE TABLE bookings
2+
(
3+
id BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY,
4+
uuid VARCHAR(255) NOT NULL,
5+
version BIGINT NOT NULL,
6+
campsite_id BIGINT NOT NULL,
7+
email VARCHAR(50) NOT NULL,
8+
full_name VARCHAR(50) NOT NULL,
9+
start_date DATE NOT NULL,
10+
end_date DATE NOT NULL,
11+
active BOOLEAN NOT NULL,
12+
created_at TIMESTAMP NOT NULL,
13+
updated_at TIMESTAMP NOT NULL,
14+
CONSTRAINT pk_bookings PRIMARY KEY (id)
15+
);
16+
17+
ALTER TABLE bookings
18+
ADD CONSTRAINT uc_bookings_uuid UNIQUE (uuid);
19+
20+
ALTER TABLE bookings
21+
ADD CONSTRAINT fk_campsites_id
22+
FOREIGN KEY (campsite_id) REFERENCES campsites(id)
23+
ON DELETE RESTRICT ON UPDATE RESTRICT;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CREATE TABLE campsites
2+
(
3+
id BIGINT NOT NULL AUTO_INCREMENT,
4+
capacity INT NOT NULL,
5+
restrooms BOOLEAN NOT NULL,
6+
drinking_water BOOLEAN NOT NULL,
7+
picnic_table BOOLEAN NOT NULL,
8+
fire_pit BOOLEAN NOT NULL,
9+
active BOOLEAN NOT NULL,
10+
created_at TIMESTAMP(6) NOT NULL,
11+
updated_at TIMESTAMP(6) NOT NULL,
12+
CONSTRAINT pk_campsites PRIMARY KEY (id)
13+
);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
CREATE TABLE bookings
2+
(
3+
id BIGINT NOT NULL AUTO_INCREMENT,
4+
uuid VARCHAR(255) NOT NULL,
5+
version BIGINT NOT NULL,
6+
campsite_id BIGINT NOT NULL,
7+
email VARCHAR(50) NOT NULL,
8+
full_name VARCHAR(50) NOT NULL,
9+
start_date DATE NOT NULL,
10+
end_date DATE NOT NULL,
11+
active BOOLEAN NOT NULL,
12+
created_at TIMESTAMP(6) NOT NULL,
13+
updated_at TIMESTAMP(6) NOT NULL,
14+
CONSTRAINT pk_bookings PRIMARY KEY (id)
15+
);
16+
17+
ALTER TABLE bookings
18+
ADD CONSTRAINT uc_bookings_uuid UNIQUE (uuid);
19+
20+
ALTER TABLE bookings
21+
ADD CONSTRAINT fk_campsites_id
22+
FOREIGN KEY (campsite_id) REFERENCES campsites(id)
23+
ON DELETE RESTRICT ON UPDATE RESTRICT;

0 commit comments

Comments
 (0)