Как 2 Databasemigration для приложения SpringBoot в 2019 году
Я хотел бы знать, как правильно выполнить Databasemigration для моего приложения SpringBoot. До сих пор я много читал о Liquibase и немного о Flyaway, так как они оба упомянуты в Springdoc. Но Liquibase и Flyaway не могут делать то, что я хочу, из коробки. Ofc читать руководства по плагинам и т. Д., Но мы вернемся к этому позже
Что я хочу:
В лучшем случае это будет процесс Databasemigration, который работает почти автоматически. Вы должны запустить задачу gradle и создать diffChangelog, дважды проверить его, а затем развернуть / перенести. Если это уместно, мы развертываем просто как банку и не имеем докера и т. Д.
Что я сделал до сих пор:
Я пытался использовать Liquibase, плагин gradle и плагин liquibase-hibernate. Я столкнулся с множеством ошибок, и на данный момент он больше не падает, но все еще не делает то, что должен делать. Который берет сущности постоянства и создает различие между ними и существующим БД. Описанные в этом руководстве, это руководство и множество других. Но не уверен, работает ли он вообще, потому что плагин liquibase-hibernate не обновлялся в течение 2 лет.
Теперь мой вопрос. Есть ли альтернатива плагину Liquibase-Hibernate или даже полностью жидкая база, которая позволяет мне делать то, что я описал? Если нет, то как мне заставить это работать? XD
Вот код: build.gralde
apply plugin: "org.liquibase.gradle"
buildscript {
ext {
springBootVersion = '2.0.5.RELEASE'
gitProperiesPluginVersion = '1.5.2'
}
repositories {
jcenter()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}",
"org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5",
"org.ajoberstar:grgit:1.5.0",
"mysql:mysql-connector-java:8.0.12",
"gradle.plugin.com.gorylenko.gradle-git-properties:gradle-git-properties:${gitProperiesPluginVersion}",
"com.github.fgiannesini.libsass.gradle.plugin:libsass-gradle-plugin:+",
"org.liquibase:liquibase-gradle-plugin:2.0.1")
}
}
//retrieve spring datasource properties from application.properties
def applicationProps = new Properties()
//TODO change to production
applicationProps.load(new FileInputStream("src/main/resources/application-local-mysql.properties"))
liquibase {
activities {
main{
url applicationProps.getProperty('spring.datasource.url')
username applicationProps.getProperty('spring.datasource.username')
password applicationProps.getProperty('spring.datasource.password')
driver applicationProps.getProperty('spring.datasource.driver-class-name')
referenceUrl applicationProps.getProperty('liquibaseDiff.referenceUrl')
changeLogFile "$projectDir/src/main/resources/db/changelog/db.changelog_initial_${new Date().format('yyyyMMdd_HHmmss')}.xml"
logLevel 'debug'
}
}
}
dependencies {
//Liquibase for Databasemigration
compile group: 'org.liquibase', name: 'liquibase-core'
liquibaseRuntime group: 'org.liquibase', name: 'liquibase-core'
liquibaseRuntime "mysql:mysql-connector-java:6.0.6"
liquibaseRuntime "org.hibernate:hibernate-core"
liquibaseRuntime "org.liquibase.ext:liquibase-hibernate5:3.6"
liquibaseRuntime "org.springframework.boot:spring-boot-starter-data-jpa"
liquibaseRuntime files('src/main')
liquibaseRuntime group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
//liquibaseRuntime sourceSets.main.output
}
приложения локальный MySQL-свойство
#Datasource Configuration
spring.datasource.url=jdbc:mysql://localhost:3306/negoisst4?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull&useSSL=false&nullNamePatternMatchesAll=true
spring.datasource.username=root
spring.datasource.password=
spring.datasource.platform=mysql
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
liquibaseDiff.referenceUrl=hibernate:spring:com.my.packages?dialect=org.hibernate.dialect.MySQL5Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
Когда я запускаю diffChangeLog, он создает тот, который только отбрасывает все. Вот некоторые результаты, когда я запускаю diff:
DEBUG 02.03.19 10:53: liquibase: Connected to root@localhost@jdbc:mysql://localhost:3306/negoisst4?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull&useSSL=false&nullNamePatternMatchesAll=true
DEBUG 02.03.19 10:53: liquibase: Setting auto commit to false from true
DEBUG 02.03.19 10:53: liquibase: Connected to null@hibernate:spring:de.hohenheim.wi1.negoisst.model?dialect=org.hibernate.dialect.MySQL5Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
DEBUG 02.03.19 10:53: liquibase: Not adjusting the auto commit mode; it is already false
INFO 02.03.19 10:53: liquibase-hibernate: Reading hibernate configuration hibernate:spring:de.hohenheim.wi1.negoisst.model?dialect=org.hibernate.dialect.MySQL5Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
INFO 02.03.19 10:53: liquibase-hibernate: Found package de.hohenheim.wi1.negoisst.model
10:53:26.953 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Resolved classpath location [META-INF/persistence.xml] to resources []
10:53:26.958 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Resolved classpath location [de/hohenheim/wi1/negoisst/model/] to resources []
10:53:26.958 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Resolved location pattern [classpath*:de/hohenheim/wi1/negoisst/model/**/*.class] to resources []
10:53:27.003 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Log4j2LoggerProvider
.
.
.
DEBUG 02.03.19 10:53: liquibase: Computed checksum for 1551520408913 as fc2a473c724b14fe86312dab07ee3cd2
DEBUG 02.03.19 10:53: liquibase: Executing QUERY database command: select const.CONSTRAINT_NAME, COLUMN_NAME from information_schema.table_constraints const join information_schema.key_column_usage col on const.constraint_schema=col.constraint_schema and const.table_name=col.table_name and const.constraint_name=col.constraint_name where const.constraint_schema='negoisst4' and const.table_name='trust_measurement_trust_statement_answers' and const.constraint_name='uk_awuterxuh4721br8p554yeykb'order by ordinal_position
DEBUG 02.03.19 10:53: liquibase: Executing QUERY database command: select const.CONSTRAINT_NAME, COLUMN_NAME from information_schema.table_constraints const join information_schema.key_column_usage col on const.constraint_schema=col.constraint_schema and const.table_name=col.table_name and const.constraint_name=col.constraint_name where const.constraint_schema='negoisst4' and const.table_name='treatment_participant_configuration' and const.constraint_name='uk_qnfjakthv8sfhkd7r2c79h58o'order by ordinal_position
DEBUG 02.03.19 10:53: liquibase: Executing QUERY database command: select const.CONSTRAINT_NAME, COLUMN_NAME from information_schema.table_constraints const join information_schema.key_column_usage col on const.constraint_schema=col.constraint_schema and const.table_name=col.table_name and const.constraint_name=col.constraint_name where const.constraint_schema='negoisst4' and const.table_name='ase_preference_measurement_next_identified_comparisons' and const.constraint_name='uk_rpdsg51d6v7mbswdcts5r70rq'order by ordinal_position
DEBUG 02.03.19 10:53: liquibase: Executing QUERY database command: select const.CONSTRAINT_NAME, COLUMN_NAME from information_schema.table_constraints const join information_schema.key_column_usage col on const.constraint_schema=col.constraint_schema and const.table_name=col.table_name and const.constraint_name=col.constraint_name where const.constraint_schema='negoisst4' and const.table_name='negoisst_user' and const.constraint_name='uk_aeokjpmeqqqid4u9m54qf23pf'order by ordinal_position
DEBUG 02.03.19 10:53: liquibase: Executing QUERY database command: select const.CONSTRAINT_NAME, COLUMN_NAME from information_schema.table_constraints const join information_schema.key_column_usage col on const.constraint_schema=col.constraint_schema and const.table_name=col.table_name and const.constraint_name=col.constraint_name where const.constraint_schema='negoisst4' and const.table_name='dispute_resolution_participants' and const.constraint_name='uk_jh90shxowuibpegitcpy50c1m'order by ordinal_position
DEBUG 02.03.19 10:53: liquibase: Executing QUERY database command: select const.CONSTRAINT_NAME, COLUMN_NAME from information_schema.table_constraints const join information_schema.key_column_usage col on const.constraint_schema=col.constraint_schema and const.table_name=col.table_name and const.constraint_name=col.constraint_name where const.constraint_schema='negoisst4' and const.table_name='ase_pm_issue_rated_values' and const.constraint_name='uk_30bexu74whbs1xtpnmbupkggi'order by ordinal_position
DEBUG 02.03.19 10:53: liquibase: Executing QUERY database command: select const.CONSTRAINT_NAME, COLUMN_NAME from information_schema.table_constraints const join information_schema.key_column_usage col on const.constraint_schema=col.constraint_schema and const.table_name=col.table_name and const.constraint_name=col.constraint_name where const.constraint_schema='negoisst4' and const.table_name='ase_preference_measurement_conducted_paired_comparisons' and const.constraint_name='uk_13onu5our6cipfuoisy0qq7su'order by ordinal_position
DEBUG 02.03.19 10:53: liquibase: Executing QUERY database command: select const.CONSTRAINT_NAME, COLUMN_NAME from information_schema.table_constraints const join information_schema.key_column_usage col on const.constraint_schema=col.constraint_schema and const.table_name=col.table_name and const.constraint_name=col.constraint_name where const.constraint_schema='negoisst4' and const.table_name='preference_model_associated_weighted_issues' and const.constraint_name='uk_d0nk6tg0ghjaho5u4g1r71cq'order by ordinal_position
.
.
.
Changed Primary Key(s): NONE
Missing Sequence(s): NONE
Unexpected Sequence(s): NONE
Changed Sequence(s): NONE
Missing Stored Procedure(s): NONE
Unexpected Stored Procedure(s): NONE
Changed Stored Procedure(s): NONE
Missing Table(s): NONE
Unexpected Table(s):
agenda
agenda_aud
consent_form
email_verification_token
event
event_reminder_date
experiment
hibernate_sequence
issue
issue_aud
issue_group
issue_group_aud
issue_group_issue_aud
issue_interval
issue_w_rated_values
message
.
.
.