Skip to content

Commit

Permalink
Upgrade to Liquibase 3.10.1 (also liquibase-hibernate5) (#175)
Browse files Browse the repository at this point in the history
* Upgrade to Liquibase 3.10.1 (also liquibase-hibernate5)
     - Fixed tests by extracting changeLog part (Gradle verbose log causes polluted outputCapture)
     - Fixes GroovyChangeLogSpec if default JVM langauge is not en.
     - String comparisons are now done without spaces in tests
     - fixes #95 #100 #159
* Use openjdk8 in Travis
  • Loading branch information
robertoschwald committed Jul 14, 2020
1 parent 711b4b3 commit 66eb715
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,6 +1,6 @@
language: groovy
jdk:
- oraclejdk8
- openjdk8
before_install:
- cat /etc/hosts
- sudo hostname "$(hostname | cut -c1-63)"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -4,7 +4,7 @@

## Branches

**master** Version of the plugin compatible with Grails 3 and Hibernate 5.
**master** Version of the plugin compatible with Grails 3 / 4 and Hibernate 5.

**2.x**. Version of the plugin compatible with Grails 3 and Hibernate 4.

Expand All @@ -29,9 +29,9 @@ One popular approach is to have a root changelog named changlog.groovy (or chang
## Documentation
* Grails 2: http://grails-plugins.github.io/grails-database-migration/docs/manual/index.html
* Grails 3 (Hibernate 4): http://grails-plugins.github.io/grails-database-migration/2.0.x/index.html
* Grails 3 (Hibernate 5): http://grails-plugins.github.io/grails-database-migration/3.0.x/index.html
* Grails 3/4 (Hibernate 5): http://grails-plugins.github.io/grails-database-migration/3.0.x/index.html


## Package distribution

Software is distrbuted in [Bintray](https://bintray.com/grails/plugins/database-migration)
Software is distributed on [Bintray](https://bintray.com/grails/plugins/database-migration)
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -53,7 +53,7 @@ configurations {
dependencies {
compile "org.liquibase:liquibase-core:$liquibaseVersion"

compile('org.liquibase.ext:liquibase-hibernate5:3.7') {
compile("org.liquibase.ext:liquibase-hibernate5:$liquibaseVersion") {
exclude group: 'org.hibernate', module: 'hibernate-core'
exclude group: 'org.hibernate', module: 'hibernate-entitymanager'
exclude group: 'org.hibernate', module: 'hibernate-envers'
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
@@ -1,6 +1,6 @@
grailsVersion=3.2.1
gradleWrapperVersion=3.1
liquibaseVersion=3.6.1
liquibaseVersion=3.10.1

websiteUrl=http://grails-plugins.github.io/grails-database-migration
issueTrackerUrl=https://github.com/grails-plugins/grails-database-migration/issues
Expand Down
Expand Up @@ -51,4 +51,9 @@ abstract class DatabaseMigrationCommandSpec extends Specification {
changeLogLocation = File.createTempDir()
}


protected static extractOutput(OutputCapture outputCapture){
// outputCapture may contain debug outputs
outputCapture.toString().getAt(outputCapture.toString().indexOf("databaseChangeLog")..-1)?.replaceAll(/\s/,"")
}
}
Expand Up @@ -53,13 +53,14 @@ CREATE TABLE author (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL,
command.handle(getExecutionContext('other'))

then:
outputCapture.toString() =~ '''
String expected = extractOutput(outputCapture)
expected =~ '''
databaseChangeLog = \\{
changeSet\\(author: ".+?", id: ".+?"\\) \\{
createTable\\(tableName: "AUTHOR"\\) \\{
column\\(autoIncrement: "true", name: "ID", type: "INT"\\) \\{
constraints\\(primaryKey: "true", primaryKeyName: "PK_AUTHOR"\\)
constraints\\(nullable:"false", primaryKey: "true", primaryKeyName: "PK_AUTHOR"\\)
\\}
column\\(name: "NAME", type: "VARCHAR\\(255\\)"\\) \\{
Expand All @@ -76,7 +77,7 @@ databaseChangeLog = \\{
\\}
\\}
\\}
'''.trim()
'''.replaceAll(/\s/,"")
}

def "writes Change Log to update the database to a file given as arguments"() {
Expand All @@ -87,13 +88,13 @@ databaseChangeLog = \\{
command.handle(getExecutionContext('other', outputChangeLog.name))

then:
outputChangeLog.text =~ '''
outputChangeLog.text?.replaceAll(/\s/,"") =~ '''
databaseChangeLog = \\{
changeSet\\(author: ".+?", id: ".+?"\\) \\{
createTable\\(tableName: "AUTHOR"\\) \\{
column\\(autoIncrement: "true", name: "ID", type: "INT"\\) \\{
constraints\\(primaryKey: "true", primaryKeyName: "PK_AUTHOR"\\)
constraints\\(nullable:"false", primaryKey: "true", primaryKeyName: "PK_AUTHOR"\\)
\\}
column\\(name: "NAME", type: "VARCHAR\\(255\\)"\\) \\{
Expand All @@ -110,7 +111,7 @@ databaseChangeLog = \\{
\\}
\\}
\\}
'''.trim()
'''.replaceAll(/\s/,"")
}

def "an error occurs if the otherEnv parameter is not specified"() {
Expand Down
Expand Up @@ -33,13 +33,13 @@ CREATE TABLE author (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL,
command.handle(getExecutionContext())

then:
outputCapture.toString() =~ '''
extractOutput(outputCapture) =~ '''
databaseChangeLog = \\{
changeSet\\(author: ".*?", id: ".*?"\\) \\{
createTable\\(tableName: "AUTHOR"\\) \\{
column\\(autoIncrement: "true", name: "ID", type: "INT"\\) \\{
constraints\\(primaryKey: "true", primaryKeyName: "PK_AUTHOR"\\)
constraints\\(nullable: "false", primaryKey: "true", primaryKeyName: "PK_AUTHOR"\\)
\\}
column\\(name: "NAME", type: "VARCHAR\\(255\\)"\\) \\{
Expand All @@ -51,7 +51,7 @@ databaseChangeLog = \\{
changeSet\\(author: ".*?", id: ".*?"\\) \\{
createTable\\(tableName: "BOOK"\\) \\{
column\\(autoIncrement: "true", name: "ID", type: "INT"\\) \\{
constraints\\(primaryKey: "true", primaryKeyName: "PK_BOOK"\\)
constraints\\(nullable: "false", primaryKey: "true", primaryKeyName: "PK_BOOK"\\)
\\}
column\\(name: "TITLE", type: "VARCHAR\\(255\\)"\\) \\{
Expand All @@ -64,7 +64,7 @@ databaseChangeLog = \\{
\\}
\\}
\\}
'''.trim()
'''.replaceAll(/\s/, "")
}

def "generates an initial changelog from the database to a file given as arguments"() {
Expand All @@ -75,13 +75,13 @@ databaseChangeLog = \\{
command.handle(getExecutionContext(outputChangeLog.name))

then:
outputChangeLog.text =~ '''
outputChangeLog.text?.replaceAll(/\s/, "") =~ '''
databaseChangeLog = \\{
changeSet\\(author: ".*?", id: ".*?"\\) \\{
createTable\\(tableName: "AUTHOR"\\) \\{
column\\(autoIncrement: "true", name: "ID", type: "INT"\\) \\{
constraints\\(primaryKey: "true", primaryKeyName: "PK_AUTHOR"\\)
constraints\\(nullable: "false", primaryKey: "true", primaryKeyName: "PK_AUTHOR"\\)
\\}
column\\(name: "NAME", type: "VARCHAR\\(255\\)"\\) \\{
Expand All @@ -93,7 +93,7 @@ databaseChangeLog = \\{
changeSet\\(author: ".*?", id: ".*?"\\) \\{
createTable\\(tableName: "BOOK"\\) \\{
column\\(autoIncrement: "true", name: "ID", type: "INT"\\) \\{
constraints\\(primaryKey: "true", primaryKeyName: "PK_BOOK"\\)
constraints\\(nullable: "false", primaryKey: "true", primaryKeyName: "PK_BOOK"\\)
\\}
column\\(name: "TITLE", type: "VARCHAR\\(255\\)"\\) \\{
Expand All @@ -106,6 +106,6 @@ databaseChangeLog = \\{
\\}
\\}
\\}
'''.trim()
'''.replaceAll(/\s/, "")
}
}
Expand Up @@ -27,13 +27,13 @@ class DbmGenerateGormChangelogCommandSpec extends ApplicationContextDatabaseMigr
command.handle(getExecutionContext())

then:
outputCapture.toString() =~ '''
extractOutput(outputCapture) =~ '''
databaseChangeLog = \\{
changeSet\\(author: ".+?", id: ".+?"\\) \\{
createTable\\(tableName: "author"\\) \\{
column\\(autoIncrement: "true", name: "id", type: "BIGINT"\\) \\{
constraints\\(primaryKey: "true", primaryKeyName: "authorPK"\\)
constraints\\(nullable: "false", primaryKey: "true", primaryKeyName: "authorPK"\\)
\\}
column\\(name: "version", type: "BIGINT"\\) \\{
Expand All @@ -49,7 +49,7 @@ databaseChangeLog = \\{
changeSet\\(author: ".+?", id: ".+?"\\) \\{
createTable\\(tableName: "book"\\) \\{
column\\(autoIncrement: "true", name: "id", type: "BIGINT"\\) \\{
constraints\\(primaryKey: "true", primaryKeyName: "bookPK"\\)
constraints\\(nullable: "false", primaryKey: "true", primaryKeyName: "bookPK"\\)
\\}
column\\(name: "version", type: "BIGINT"\\) \\{
Expand All @@ -70,7 +70,7 @@ databaseChangeLog = \\{
addForeignKeyConstraint\\(baseColumnNames: "author_id", baseTableName: "book", constraintName: "FK.+?", deferrable: "false", initiallyDeferred: "false", referencedColumnNames: "id", referencedTableName: "author", validate: "true"\\)
\\}
\\}
'''.trim()
'''.replaceAll(/\s/,"")
}

def "writes Change Log to copy the current state of the database to a file given as arguments"() {
Expand All @@ -81,14 +81,14 @@ databaseChangeLog = \\{
command.handle(getExecutionContext(filename))

then:
def output = new File(changeLogLocation, filename).text
def output = new File(changeLogLocation, filename).text?.replaceAll(/\s/, "")
output =~ '''
databaseChangeLog = \\{
changeSet\\(author: ".+?", id: ".+?"\\) \\{
createTable\\(tableName: "author"\\) \\{
column\\(autoIncrement: "true", name: "id", type: "BIGINT"\\) \\{
constraints\\(primaryKey: "true", primaryKeyName: "authorPK"\\)
constraints\\(nullable: "false", primaryKey: "true", primaryKeyName: "authorPK"\\)
\\}
column\\(name: "version", type: "BIGINT"\\) \\{
Expand All @@ -104,7 +104,7 @@ databaseChangeLog = \\{
changeSet\\(author: ".+?", id: ".+?"\\) \\{
createTable\\(tableName: "book"\\) \\{
column\\(autoIncrement: "true", name: "id", type: "BIGINT"\\) \\{
constraints\\(primaryKey: "true", primaryKeyName: "bookPK"\\)
constraints\\(nullable: "false", primaryKey: "true", primaryKeyName: "bookPK"\\)
\\}
column\\(name: "version", type: "BIGINT"\\) \\{
Expand All @@ -125,7 +125,7 @@ databaseChangeLog = \\{
addForeignKeyConstraint\\(baseColumnNames: "author_id", baseTableName: "book", constraintName: "FK.+?", deferrable: "false", initiallyDeferred: "false", referencedColumnNames: "id", referencedTableName: "author", validate: "true"\\)
\\}
\\}
'''.trim()
'''.replaceAll(/\s/, "")
}

def "an error occurs if changeLogFile already exists"() {
Expand Down
Expand Up @@ -31,14 +31,14 @@ class DbmGormDiffCommandSpec extends ApplicationContextDatabaseMigrationCommandS
command.handle(getExecutionContext())

then:
def output = outputCapture.toString()
output =~ '''
def output = extractOutput(outputCapture).replaceAll(/\s/,"")
output ==~ '''
databaseChangeLog = \\{
changeSet\\(author: ".+?", id: ".+?"\\) \\{
createTable\\(tableName: "book"\\) \\{
column\\(autoIncrement: "true", name: "id", type: "BIGINT"\\) \\{
constraints\\(primaryKey: "true", primaryKeyName: "bookPK"\\)
constraints\\(nullable: "false", primaryKey: "true", primaryKeyName: "bookPK"\\)
\\}
column\\(name: "version", type: "BIGINT"\\) \\{
Expand All @@ -59,7 +59,7 @@ databaseChangeLog = \\{
addForeignKeyConstraint\\(baseColumnNames: "author_id", baseTableName: "book", constraintName: "FK.+?", deferrable: "false", initiallyDeferred: "false", referencedColumnNames: "id", referencedTableName: "author", validate: "true"\\)
\\}
\\}
'''.trim()
'''.replaceAll(/\s/,"")
}

def "diffs GORM classes against a database and generates a changelog to a file given as arguments"() {
Expand All @@ -70,14 +70,14 @@ databaseChangeLog = \\{
command.handle(getExecutionContext(filename))

then:
def output = new File(changeLogLocation, filename).text
def output = new File(changeLogLocation, filename).text?.replaceAll(/\s/,"")
output =~ '''
databaseChangeLog = \\{
changeSet\\(author: ".+?", id: ".+?"\\) \\{
createTable\\(tableName: "book"\\) \\{
column\\(autoIncrement: "true", name: "id", type: "BIGINT"\\) \\{
constraints\\(primaryKey: "true", primaryKeyName: "bookPK"\\)
constraints\\(nullable:"false", primaryKey: "true", primaryKeyName: "bookPK"\\)
\\}
column\\(name: "version", type: "BIGINT"\\) \\{
Expand All @@ -98,7 +98,7 @@ databaseChangeLog = \\{
addForeignKeyConstraint\\(baseColumnNames: "author_id", baseTableName: "book", constraintName: "FK.+?", deferrable: "false", initiallyDeferred: "false", referencedColumnNames: "id", referencedTableName: "author", validate: "true"\\)
\\}
\\}
'''.trim()
'''.replaceAll(/\s/,"")
}

def "an error occurs if changeLogFile already exists"() {
Expand Down
Expand Up @@ -4,13 +4,13 @@ import grails.core.GrailsApplication
import liquibase.exception.ValidationFailedException
import org.grails.plugins.databasemigration.command.*


class GroovyChangeLogSpec extends ApplicationContextDatabaseMigrationCommandSpec {

static List<String> calledBlocks

def setup() {
calledBlocks = []
Locale.setDefault(new Locale("en", "US"))
}

def "updates a database with Groovy Change"() {
Expand Down Expand Up @@ -66,11 +66,9 @@ databaseChangeLog = {
calledBlocks == ['validate', 'change']
}



def "stops processing by calling the error method"() {
given:
def command = createCommand(DbmUpdateCommand)
DbmUpdateCommand command = (DbmUpdateCommand)createCommand(DbmUpdateCommand)
command.changeLogFile << """
databaseChangeLog = {
changeSet(author: "John Smith", id: "1") {
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/logback.groovy
Expand Up @@ -11,6 +11,8 @@ root(ERROR, ['STDOUT'])

logger("org.grails", DEBUG, ['STDOUT'], false)
logger("liquibase", DEBUG, ['STDOUT'], false)
logger("org.grails.datastore.gorm.GormEnhancer", INFO, ['STDOUT'], false)
logger("org.grails.plugin.datasource.TomcatJDBCPoolMBeanExporter", WARN, ['STDOUT'], false)



0 comments on commit 66eb715

Please sign in to comment.