diff --git a/build.gradle b/build.gradle index e7540a9f5..1fa195e85 100644 --- a/build.gradle +++ b/build.gradle @@ -38,6 +38,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'javax.cache:cache-api' implementation 'jakarta.xml.bind:jakarta.xml.bind-api' + implementation 'org.springframework.boot:spring-boot-starter-liquibase' runtimeOnly 'org.springframework.boot:spring-boot-starter-actuator' runtimeOnly "org.webjars:webjars-locator-lite:${webjarsLocatorLiteVersion}" runtimeOnly "org.webjars.npm:bootstrap:${webjarsBootstrapVersion}" diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties new file mode 100644 index 000000000..cddf498c7 --- /dev/null +++ b/src/main/resources/application-dev.properties @@ -0,0 +1,3 @@ +spring.liquibase.contexts=dev + + diff --git a/src/main/resources/application-mysql.properties b/src/main/resources/application-mysql.properties index e23dfa605..870ba8444 100644 --- a/src/main/resources/application-mysql.properties +++ b/src/main/resources/application-mysql.properties @@ -4,4 +4,4 @@ spring.datasource.url=${MYSQL_URL:jdbc:mysql://localhost/petclinic} spring.datasource.username=${MYSQL_USER:petclinic} spring.datasource.password=${MYSQL_PASS:petclinic} # SQL is written to be idempotent so this is safe -spring.sql.init.mode=always +spring.sql.init.mode=never diff --git a/src/main/resources/application-postgres.properties b/src/main/resources/application-postgres.properties index b265d7e5b..39ba0315c 100644 --- a/src/main/resources/application-postgres.properties +++ b/src/main/resources/application-postgres.properties @@ -4,4 +4,4 @@ spring.datasource.url=${POSTGRES_URL:jdbc:postgresql://localhost/petclinic} spring.datasource.username=${POSTGRES_USER:petclinic} spring.datasource.password=${POSTGRES_PASS:petclinic} # SQL is written to be idempotent so this is safe -spring.sql.init.mode=always +spring.sql.init.mode=never diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties new file mode 100644 index 000000000..c79578136 --- /dev/null +++ b/src/main/resources/application-prod.properties @@ -0,0 +1 @@ +spring.liquibase.contexts=prod diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 6ed985654..b7ebb873b 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,8 +1,14 @@ # database init, supports mysql too -database=h2 -spring.sql.init.schema-locations=classpath*:db/${database}/schema.sql -spring.sql.init.data-locations=classpath*:db/${database}/data.sql +#database=h2 +#spring.sql.init.schema-locations=classpath*:db/${database}/schema.sql +#spring.sql.init.data-locations=classpath*:db/${database}/data.sql +#liquibase +spring.sql.init.mode=never +spring.liquibase.enabled=true +spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.yaml +spring.liquibase.show-summary=SUMMARY +spring.liquibase.show-summary-output=LOG # Web spring.thymeleaf.mode=HTML @@ -20,6 +26,7 @@ management.endpoints.web.exposure.include=* logging.level.org.springframework=INFO # logging.level.org.springframework.web=DEBUG # logging.level.org.springframework.context.annotation=TRACE +logging.level.liquibase=INFO # Maximum time static resources should be cached spring.web.resources.cache.cachecontrol.max-age=12h diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml new file mode 100644 index 000000000..f8fa682fe --- /dev/null +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -0,0 +1,69 @@ +databaseChangeLog: + - changeSet: + id: 001-schema-h2 + author: you + dbms: h2 + changes: + - sqlFile: + path: db/h2/schema.sql + relativeToChangelogFile: false + splitStatements: true + stripComments: true + + - changeSet: + id: 002-schema-mysql + author: you + dbms: mysql + changes: + - sqlFile: + path: db/mysql/schema.sql + relativeToChangelogFile: false + splitStatements: true + stripComments: true + + - changeSet: + id: 003-schema-postgres + author: you + dbms: postgresql + changes: + - sqlFile: + path: db/postgres/schema.sql + relativeToChangelogFile: false + splitStatements: true + stripComments: true + + - changeSet: + id: 101-data-h2 + author: you + dbms: h2 + context: dev + changes: + - sqlFile: + path: db/h2/data.sql + relativeToChangelogFile: false + splitStatements: true + stripComments: true + + - changeSet: + id: 102-data-mysql + author: you + dbms: mysql + context: dev + changes: + - sqlFile: + path: db/mysql/data.sql + relativeToChangelogFile: false + splitStatements: true + stripComments: true + + - changeSet: + id: 103-data-postgres + author: you + dbms: postgresql + context: dev + changes: + - sqlFile: + path: db/postgres/data.sql + relativeToChangelogFile: false + splitStatements: true + stripComments: true