简体   繁体   中英

grails database migration plugin problems after upgrade to grails 3

I was using a previous version grails-database-migration plugin for a while and never had any big issues with it. However, lately I upgraded the whole project to grails 3.0.9 and did some additional development, the behavior as follows:

  1. Imported the current prod DB structure into local machine (that DB copy is without the latest changes and new entities)

  2. Execute: grails -Dgrails.env=staging dbm-gorm-diff changlog.xml

What I expected at this point is new changlog.xml file with all changes of existing entities and new ones.

What I get:

  • Newly defined entities automatically got added into the DB.
  • The changes in changlog.xml only included the changes of already existing tables, such as: 在此输入图像描述

also, If I try running grails -Dgrails.env=staging run-app

ERROR grails.boot.GrailsApp - Application startup failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springLiquibase_dataSource': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: liquibase.integration.spring.SpringLiquibase.createDatabase(Ljava/sql/Connection;Lliquibase/resource/ResourceAccessor;)Lliquibase/database/Database; FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':bootRun'. Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1 ...

...

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. | Error Failed to start server (Use --stacktrace to see the full trace)

Here is the portion of my application.yml

dataSource:
    pooled: true
    url: jdbc:mysql://127.0.0.1:3306/triz?useUnicode=yes&characterEncoding=UTF-8
    driverClassName: "com.mysql.jdbc.Driver"
    jmxExport: true
    username: root
    password: password
    dialect: org.hibernate.dialect.MySQL5InnoDBDialect
    properties:
        jmxEnabled: true
        initialSize: 5
        maxActive: 50
        minIdle: 5
        maxIdle: 25
        maxWait: 10000
        maxAge: 600000
        timeBetweenEvictionRunsMillis: 5000
        minEvictableIdleTimeMillis: 60000
        validationQuery: SELECT 1
        validationQueryTimeout: 3
        validationInterval: 15000
        testOnBorrow: true
        testWhileIdle: true
        testOnReturn: false
        jdbcInterceptors: ConnectionState
        defaultTransactionIsolation: 2

environments:
    development:
        dataSource:
            dbCreate: create
#            url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
    test:
        dataSource:
            dbCreate: update
            url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
    staging:
        dataSource:
            url: jdbc:mysql://127.0.0.1:3306/triz_staging?useUnicode=yes&characterEncoding=UTF-8

and gradle.build

buildscript {
    ext {
        grailsVersion = project.grailsVersion
    }
    repositories {
        mavenCentral()
        mavenLocal()
        maven { url "https://repo.grails.org/grails/core" }
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsVersion"
        classpath 'com.bertramlabs.plugins:asset-pipeline-gradle:2.5.0'
//        classpath 'com.bertramlabs.plugins:less-asset-pipeline:2.6.7'
        classpath "org.grails.plugins:hibernate:4.3.10.5"
        classpath 'org.grails.plugins:database-migration:2.0.0.RC4'
    }
}
...
...
dependencies {
 ...
    compile 'org.liquibase:liquibase-core:3.3.2'
    runtime 'org.grails.plugins:database-migration:2.0.0.RC4'
}

UPDATE I have another way to approach this problem: My plan was to generate a changelog based on my current prod DB and then generate a diff for the changes I made. Sounds simple and straightforward; however, it didn't work out as expected. Here is what I did:

  1. Dumped prod DB
  2. Removed liquibase tables
  3. Run: grails dbm-generate-changelog changelog-init.xml --add At this point, I expected changelog-init.xml to contain the current state of DB. But, instead it applied the changes based on my models first, and then tried generating the diff. Eventually, I ended up with a changelog including my entire existing DB with changes applied from gorm.

What am I doing wrong here?

Additional Observations

It looks like, whenever I try to run ANY migration related commands, grails applies all the changes before that, even through my config says:

staging:
        dataSource:
            dbCreate: ~
            url: jdbc:mysql://127.0.0.1:3306/triz_staging?useUnicode=yes&characterEncoding=UTF-8
            properties:
                jmxEnabled: true

Also tried completely removing dbCreate . Didn't change anything... I am done, have no idea where to move next!!!

Well, here is a deal... I am not sure if that was the real reason, but all I did is moved datasource config from application.yml to application.groovy and everything got back to normal.

I would be happy to hear thoughts.

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM