diff --git a/build.gradle.kts b/build.gradle.kts index 8e4216d..17d2ee9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,6 +5,7 @@ plugins { alias(libs.plugins.versions) alias(libs.plugins.version.catalog.update) + alias(libs.plugins.flyway) alias(libs.plugins.gradle.git.properties) alias(libs.plugins.spotless) alias(libs.plugins.sonarqube) @@ -16,6 +17,7 @@ plugins { buildscript { dependencies { classpath(libs.spring.boot.gradle.plugin) + classpath(libs.flyway.gradle.plugin) } } @@ -203,6 +205,8 @@ dependencies { implementation(libs.spring.boot.starter) implementation(libs.spring.boot.starter.data.jpa) implementation(libs.google.cloud.spanner.jdbc) + implementation(libs.flyway.core) + implementation(libs.flyway.spanner) } gitProperties { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 187e249..b9aa54f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,6 @@ [versions] easy-random = "6.2.1" +flyway = "10.4.1" groovy = "4.0.7" kotlin = "1.9.20" spock = "2.4-M1-groovy-4.0" @@ -8,6 +9,9 @@ spring-boot = "3.2.1" [libraries] commons-lang3 = "org.apache.commons:commons-lang3:3.13.0" easy-random = { module = "io.github.dvgaba:easy-random-core", version.ref = "easy-random" } +flyway-core = { module = "org.flywaydb:flyway-core", version.ref = "flyway" } +flyway-spanner = { module = "org.flywaydb:flyway-gcp-spanner", version.ref = "flyway" } +flyway-gradle-plugin = { module = "org.flywaydb:flyway-gradle-plugin", version.ref = "flyway" } groovy = { module = "org.apache.groovy:groovy", version.ref = "groovy" } groovy-sql = { module = "org.apache.groovy:groovy-sql", version.ref = "groovy" } guava = "com.google.guava:guava:32.1.3-jre" @@ -29,6 +33,7 @@ google-cloud-spanner-jdbc = "com.google.cloud:google-cloud-spanner-jdbc:2.15.0" google-cloud-spanner-hibernate = "com.google.cloud:google-cloud-spanner-hibernate-dialect:3.0.3" [plugins] +flyway = { id = "org.flywaydb.flyway", version.ref = "flyway" } gradle-git-properties = "com.gorylenko.gradle-git-properties:2.4.1" sonarqube = "org.sonarqube:4.4.1.3373" spotless = "com.diffplug.spotless:6.22.0" diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 529cccd..b484364 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -33,6 +33,15 @@ spring: time-zone: UTC main: allow-bean-definition-overriding: true + flyway: + url: ${spring.datasource.url} + driver-class-name: ${spring.datasource.driver-class-name} + enabled: true + baseline-on-migrate: true + validate-on-migrate: false + outOfOrder: false + locations: classpath:/migration + connect-retries: 5 server: port: ${PORT:8080} diff --git a/src/main/resources/migration/V1_0_0_0__init_schema.sql b/src/main/resources/migration/V1_0_0_0__init_schema.sql new file mode 100644 index 0000000..8afa037 --- /dev/null +++ b/src/main/resources/migration/V1_0_0_0__init_schema.sql @@ -0,0 +1,10 @@ +START BATCH DDL; + +CREATE TABLE echo +( + id STRING(36) NOT NULL, + message STRING(255) NOT NULL, + timestamp TIMESTAMP NOT NULL, +) PRIMARY KEY (id); + +RUN BATCH;