简体   繁体   中英

Grails db migration not being applied

I am using Grails 2.4.3 and the database-migration:1.4.0 plugin.

I have created a simple Domain class called Mod. I am able to create the groovy based changelog using dbm-generate-gorm-changelog changelog.groovy . This correctly generates the file. I then execute dbm-update which reports:

|Starting dbm-update for database sa @ jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000
|Finished dbm-update

However, there are no table created in the database and running dvm-status returns:

|Starting dbm-status for database sa @ jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
1 change sets have not been applied to SA@jdbc:h2:mem:devDb
     changelog.groovy::1413897188349-1::clarkrichey (generated)
|Finished dbm-status 

My development environment configuration from DataSource.groovy is as follows:

 development {
        dataSource {
//            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
        }
    }

The issue centers around the fact you are using an in-memory instance of h2. Thus, nothing is saved between application launches. If you want a persistent database then change your url to use a file based instance.

development {
  dataSource {
    dbCreate = "none" // one of 'create', 'create-drop', 'update', 'validate', ''
    url = "jdbc:h2:file:/path/to/save/to/devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
  }
}

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