How to translate <createTable> to AutobaseDSL

22 views
Skip to first unread message

karste...@googlemail.com

unread,
Feb 7, 2009, 1:01:34 PM2/7/09
to Autobase
Hi,

while AutoBase works great for simple refactorings like
<addLookupTable> and even <sql) (once you figured out how autobase
maps params to the api), i'm struggling with the translation of nested
refactoring-tags like <createTable> (this might be because i'm new to
grails/groovy, though).

How would one translate the following liquibase-xml (from the docs) to
autobase (if possible at all):

<createTable tableName="person">
<column name="id" type="int">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="firstname" type="varchar(255)"/>
<column name="lastname" type="varchar(255)"/>
<column name="username" type="varchar(255)">
<constraints unique="true" nullable="false"/>
</column>
<column name="testid" type="int" />
</createTable>


Thank for your help!

Kind regards,

Karsten

Robert Fischer

unread,
Feb 8, 2009, 5:54:26 PM2/8/09
to grails-...@googlegroups.com
createTable(tableName:'person') {
column(name:'id', type:'int') {
constraints(primaryKey:'true', nullable:'false')
}
column(name:'firstname', type:'varchar(255)')
column(name:'lastname', type:'varchar(255)')
column(name:'username', type:'varchar(255)') {
constraints(unique:'true', nullable:'false')
}
column(name:'testid' type:'int')
}

If that doesn't work for you, let me know.

~~ Robert.
--
~~ Robert Fischer.
Grails Trainining http://GroovyMag.com/training
Smokejumper Consulting http://SmokejumperIT.com
Enfranchised Mind Blog http://EnfranchisedMind.com/blog

Check out my book, "Grails Persistence with GORM and GSQL"!
http://www.smokejumperit.com/redirect.html

karste...@googlemail.com

unread,
Feb 9, 2009, 6:13:12 AM2/9/09
to Autobase
Ho Robert,

> createTable(tableName:'person') {
>         column(name:'id', type:'int') {
>                 constraints(primaryKey:'true', nullable:'false')
>         }
>         column(name:'firstname', type:'varchar(255)')
>         column(name:'lastname', type:'varchar(255)')
>         column(name:'username', type:'varchar(255)') {
>                 constraints(unique:'true', nullable:'false')
>         }
>         column(name:'testid' type:'int')
>
> }

That's exactly what I tried after reading the autobase example
page ;-)
Unfortunately it does not work but throws the following exception:

liquibase.exception.ValidationFailedException: Validation Failed:
1 changes have validation failures
liquibase.exception.InvalidChangeDefinitionException:
createTable in '<removedchangesetid>' is invalid: No columns defined
at liquibase.DatabaseChangeLog.validate(DatabaseChangeLog.java:
119)
at liquibase.LiquibaseDsl.update(LiquibaseDsl.groovy:86)
at Autobase.migrate(Autobase.groovy:41)
at AutobaseGrailsPlugin$__clinit__closure7.doCall
(AutobaseGrailsPlugin.groovy:50)
at AutobaseGrailsPlugin.invokeMethod
(AutobaseGrailsPlugin.groovy)
at AutobaseGrailsPlugin$_closure2.doCall
(AutobaseGrailsPlugin.groovy:82)


I've already tried something like that:

createTable(tableName:'person',
columns: [
column(name:'id', type:'int',
constraints: constraints(primaryKey:'true',
nullable:'false')
),
column(name:'firstname', type:'varchar(255)'),
column(name:'lastname', type:'varchar(255)'),
column(name:'username', type:'varchar(255)',
constraints: constraints(unique:'true',
nullable:'false')
),
column(name:'testid' type:'int')
]
)

But I looks weird and does not work either :-/

Any ideas?

Kind regards,

Karsten
> Enfranchised Mind Bloghttp://EnfranchisedMind.com/blog

Robert Fischer

unread,
Feb 9, 2009, 9:10:21 AM2/9/09
to grails-...@googlegroups.com
Update to 0.8.1 -- this is the regression I was talking about in the release announcement.

I've attached the ChangeLog I use to smoke-test Autobase: it's the translated version of the one
used by Liquibase itself. Take a look at how things work in there.

~~ Robert.
Smokejumper Consulting http://SmokejumperIT.com
Enfranchised Mind Blog http://EnfranchisedMind.com/blog
common.tests.changelog.groovy

karste...@googlemail.com

unread,
Feb 10, 2009, 9:14:15 AM2/10/09
to Autobase
Hi Robert,

did update to 0.8.1 but now I get an java.lang.NoClassDefFoundError
for org/codehaus/groovy/runtime/callsite/Callsite when I run my grails-
app.
I think you've had the problem too (http://groups.google.com/group/
groovymn/browse_thread/thread/85593dd7d9c3fe79?pli=1) but I didn't get
how to fix it from that thread :-/

Did i do something wrong (i simply uninstalled the plugin and re-
installed the new version) or do I have upgrade my grails-version
(using 1.04)?

Kind regards,

Karsten


On 9 Feb., 15:10, Robert Fischer <robert.fisc...@smokejumperit.com>
wrote:
> [common.tests.changelog.groovy15 KB ]property( name: "table.name", value: "parameter_table" )
> property( file: "autobase.properties" )
> property( name: "column1.name", value: "updated_columnA" )
> property( name: "column2.name", value: "columnB" )
> changeSet( id: "datatypetest-1", author: "nvoxland" ){
>         validCheckSum( "e5b7b29ce3a75640858cd022501852d2" )
>         createTable( tableName: "dataTypeTest", schemaName: "" )    {
>                 column( name: "id", type: "integer" )               {
>                         constraints( primaryKey: "true", nullable: "false" )
>                 }
>
>                 column( name: "dateCol", type: "date" )
>                 column( name: "timeCol", type: "time" )
>                 column( name: "dateTimeCol", type: "dateTime" )
>         }
>
> }
>
> changeSet( id: "tagTest", author: "nvoxland" ){
>         tagDatabase( tag: "testTag" )
>
> }
>
> changeSet( id: "datatypetest-2", author: "nvoxland" ){
>         insert( tableName: "dataTypeTest" )   {
>                 column( name: "id", valueNumeric: "1" )
>                 column( name: "dateCol", valueDate: "2007-08-09" )
>                 column( name: "timeCol", valueDate: "13:14:15" )
>                 column( name: "dateTimeCol", valueDate: "2007-08-09T13:14:15" )
>         }
>
> }
>
> changeSet( id: "defaultValueTest-1", author: "nvoxland" ){
>         createTable( tableName: "defaultValueTest" )  {
>                 column( name: "id", type: "int" )
>                 column( name: "intA", type: "int" )
>                 column( name: "textA", type: "varchar(5)" )
>                 column( name: "booleanA", type: "boolean" )
>                 column( name: "dateA", type: "date" )
>                 column( name: "timeA", type: "time" )
>                 column( name: "datetimeA", type: "datetime" )
>                 column( name: "datetimeB", type: "datetime" )
>         }
>
>         addDefaultValue( tableName: "defaultValueTest", columnName: "intA", defaultValueNumeric: "1" )
>         addDefaultValue( tableName: "defaultValueTest", columnName: "textA", defaultValue: "a" )
>         addDefaultValue( tableName: "defaultValueTest", columnName: "booleanA", defaultValueBoolean: "true" )
>         addDefaultValue( tableName: "defaultValueTest", columnName: "dateA", defaultValueDate: "2007-08-09" )
>         addDefaultValue( tableName: "defaultValueTest", columnName: "timeA", defaultValueDate: "14:15:16" )
>         addDefaultValue( tableName: "defaultValueTest", columnName: "datetimeA", defaultValueDate: "2007-08-09T10:11:12" )
>         addDefaultValue( tableName: "defaultValueTest", columnName: "datetimeB", defaultValueDate: "2007-08-09 10:11:12" )
>         insert( tableName: "defaultValueTest" )       {
>                 column( name: "id", valueNumeric: "1" )
>         }
>
> }
>
> changeSet( id: "defaultValueTest-2", author: "nvoxland" ){
>         createTable( tableName: "defaultValueTest2" ) {
>                 column( name: "id", type: "int" )
>                 column( name: "intA", type: "int", defaultValueNumeric: "1" )
>                 column( name: "textA", type: "varchar(5)", defaultValue: "a" )
>                 column( name: "booleanA", type: "boolean", defaultValueBoolean: "true" )
>                 column( name: "dateA", type: "date", defaultValueDate: "2007-08-09" )
>                 column( name: "timeA", type: "time", defaultValueDate: "14:15:16" )
>                 column( name: "datetimeA", type: "datetime", defaultValueDate: "2007-08-09T10:11:12" )
>                 column( name: "datetimeB", type: "datetime", defaultValueDate: "2007-08-09 10:11:12" )
>         }
>
>         insert( tableName: "defaultValueTest2" )      {
>                 column( name: "id", valueNumeric: "1" )
>         }
>
> }
>
> changeSet( id: "compoundPrimaryKeyTest", author: "nvoxland" ){
>         createTable( tableName: "compoundPKTest" )    {
>                 column( name: "id1", type: "int" )          {
>                         constraints( primaryKey: "true", nullable: "false" )
>                 }
>
>                 column( name: "id2", type: "int" )          {
>                         constraints( primaryKey: "true", nullable: "false" )
>                 }
>
>                 column( name: "name", type: "varchar(255)" )
>         }
>
> }
>
> changeSet( id: "compoundIndexTest", author: "nvoxland" ){
>         createTable( tableName: "compoundIndexTest" ) {
>                 column( name: "id", type: "int" )           {
>                         constraints( primaryKey: "true", nullable: "false" )
>                 }
>
>                 column( name: "firstname", type: "varchar(10)" )
>                 column( name: "lastname", type: "varchar(10)" )
>         }
>
>         createIndex( indexName: "idx_compoundtest", tableName: "compoundIndexTest" )        {
>                 column( name: "firstname" )
>                 column( name: "lastname" )
>         }
>
> }
>
> changeSet( id: "commentTest", author: "nvoxland" ){
>         comment( "Creates a table and updates a value with actual SQL. Mainly for testing the comment tags" )
>         createTable( tableName: "commenttest" )       {
>                 column( name: "id", type: "int" )
>         }
>
>         sql( "insert into commenttest (id) values (1);\n            insert into commenttest (id) values (2);\n            insert into commenttest (id) values (3);" ) {
>                 comment( "Insert value into commenttest" )
>         }
>
> }
>
> changeSet( id: "add-column-test1", author: "alan" ){
>         comment( "Testing bug reported on mailing list" )
>         createTable( tableName: "ADD_COLUMN_TEST_TABLE" )     {
>                 column( name: "id", type: "int" )
>         }
>
>         addColumn( tableName: "ADD_COLUMN_TEST_TABLE" )       {
>                 column( name: "A_NEW_COLUMN", type: "int", defaultValueNumeric: "1" )             {
>                         constraints( nullable: "false" )
>                 }
>
>         }
>
> }
>
> changeSet( id: "tablespace-test1", author: "alan" ){
>         comment( "Test tablespace support. Ignored if database does not support tablespaces" )
>         createTable( tableName: "TABLESPACE_TEST_TABLE", tablespace: "liquibase2" ) {
>                 column( name: "id", type: "int" )           {
>                         constraints( nullable: "false" )
>                 }
>
>                 column( name: "name", type: "varchar(255)" )
>                 column( name: "username", type: "varchar(255)" )            {
>                         constraints( nullable: "false" )
>                 }
>
>         }
>
>         createIndex( indexName: "tablespace_index_test", tableName: "TABLESPACE_TEST_TABLE", tablespace: "liquibase2" )   {
>                 column( name: "id" )
>         }
>
>         addPrimaryKey( tableName: "TABLESPACE_TEST_TABLE", columnNames: "id", constraintName: "pk_tablespacetest", tablespace: "liquibase2" )
>         addUniqueConstraint( tableName: "TABLESPACE_TEST_TABLE", columnNames: "username", constraintName: "uq_tbsptest_usern", tablespace: "liquibase2" )
>
> }
>
> changeSet( id: "contextstest-1", author: "nvoxland" ){
>         comment( "Test how contexts work" )
>         createTable( tableName: "contextsTest" )      {
>                 column( name: "id", type: "varchar(255)" )
>         }
>
> }
>
> changeSet( id: "contextstest-2", author: "nvoxland", context: "context-a" ){
>         insert( tableName: "contextsTest" )   {
>                 column( name: "id", value: "context a" )
>         }
>
> }
>
> changeSet( id: "contextstest-3", author: "nvoxland", context: "context-a, context-b" ){
>         insert( tableName: "contextsTest" )   {
>                 column( name: "id", value: "a and b" )
>         }
>
> }
>
> changeSet( id: "contextstest-4", author: "nvoxland", context: "context-b" ){
>         insert( tableName: "contextsTest" )   {
>                 column( name: "id", value: "context b" )
>         }
>
> }
>
> changeSet( id: "contextstest-5", author: "nvoxland", context: "" ){
>         insert( tableName: "contextsTest" )   {
>                 column( name: "id", value: "empty contexts" )
>         }
>
> }
>
> changeSet( id: "contextstest-6", author: "nvoxland" ){
>         insert( tableName: "contextsTest" )   {
>                 column( name: "id", value: "null contexts" )
>         }
>
> }
>
> changeSet( id: "datatype-conversion-teset", author: "nvoxland" ){
>         createTable( tableName: "datatypeConversionTest" )    {
>                 column( name: "booleanColumn", type: "boolean" )
>                 column( name: "currencyColumn", type: "currency" )
>                 column( name: "uuidColumn", type: "uuid" )
>                 column( name: "blobColumn", type: "blob" )
>                 column( name: "clobColumn", type: "clob" )
>                 column( name: "dateColumn", type: "date" )
>                 column( name: "timeColumn", type: "time" )
>                 column( name: "datetimeColumn", type: "datetime" )
>         }
>
> }
>
> changeSet( id: "standardTypes-test", author: "nvoxland" ){
>         createTable( tableName: "standardTypesTest" ) {
>                 column( name: "timestampColumn", type: "java.sql.Types.TIMESTAMP" )
>                 column( name: "varcharColumn", type: "java.sql.Types.VARCHAR(255)" )
>                 column( name: "blobColumn", type: "java.sql.Types.BLOB" )
>                 column( name: "booleanColumn", type: "java.sql.Types.BOOLEAN" )
>         }
>
> }
>
> changeSet( id: "createTableNamedUqConst", author: "nvoxland" ){
>         createTable( tableName: "createTableNamedUqConst" )   {
>                 column( name: "id", type: "int" )           {
>                         constraints( nullable: "false", unique: "true", uniqueConstraintName: "uq_uqtest1" )
>                 }
>
>         }
>
> }
>
> changeSet( id: "createTableUnNamedUqConst", author: "nvoxland" ){
>         createTable( tableName: "createTableUnNamedUqConst" ) {
>                 column( name: "id", type: "int" )           {
>                         constraints( nullable: "false", unique: "true" )
>                 }
>
>         }
>
> }
>
> changeSet( id: "commonTypes-test", author: "nvoxland" ){
>         createTable( tableName: "commonTypesTest" )   {
>                 column( name: "intColumn", type: "int" )
>                 column( name: "floatColumn", type: "float" )
>         }
>
> }
>
> changeSet( id: "addColumnWithInitialValue-test", author: "nvoxland" ){
>         createTable( tableName: "tableWithInitialValue" )     {
>                 column( name: "id", type: "int" )
>         }
>
>         insert( tableName: "tableWithInitialValue" )  {
>                 column( name: "id", valueNumeric: "1" )
>         }
>
>         insert( tableName: "tableWithInitialValue" )  {
>                 column( name: "id", valueNumeric: "2" )
>         }
>
>         insert( tableName: "tableWithInitialValue" )  {
>                 column( name: "id", valueNumeric: "3" )
>         }
>
>         addColumn( tableName: "tableWithInitialValue" )       {
>                 column( name: "varcharColumn", type: "varchar(25)", value: "INITIAL_VALUE" )
>                 column( name: "intColumn", type: "int", valueNumeric: "2" )
>                 column( name: "dateCol", type: "date", valueDate: "2008-03-04" )
>         }
>
> }
>
> changeSet( author: "nvoxland", id: "updateTest" ){
>         createTable( tableName: "updateTest" )        {
>                 column( name: "id", type: "int" )
>                 column( name: "varcharColumn", type: "varchar(255)" )
>                 column( name: "dateCol", type: "date" )
>                 column( name: "intCol", type: "int" )
>                 column( name: "commonCol", type: "varchar(255)" )
>         }
>
>         insert( tableName: "updateTest" )     {
>                 column( name: "id", valueNumeric: "1" )
>                 column( name: "varcharColumn", value: "column 1 value" )
>                 column( name: "dateCol", valueDate: "2007-01-01" )
>                 column( name: "intCol", valueNumeric: "1" )
>         }
>
>         insert( tableName: "updateTest" )     {
>                 column( name: "id", valueNumeric: "2" )
>                 column( name: "varcharColumn", value: "column 2 value" )
>                 column( name: "dateCol", valueDate: "2007-01-02" )
>                 column( name: "intCol", valueNumeric: "2" )
>         }
>
>         insert( tableName: "updateTest" )     {
>                 column( name: "id", valueNumeric: "3" )
>                 column( name: "varcharColumn", value: "column 3 value" )
>                 column( name: "dateCol", valueDate: "2007-01-03" )
>                 column( name: "intCol", valueNumeric: "3" )
>         }
>
>         update( tableName: "updateTest" )     {
>                 column( name: "commonCol", value: "Value for everyone"...
>
> Erfahren Sie mehr »

Robert Fischer

unread,
Feb 10, 2009, 9:39:30 AM2/10/09
to grails-...@googlegroups.com
That's because v0.8.1 is intended for the 1.1 branch, and you're on 1.0.4. There's a Groovy update
between the two, which is causing the error you're seeing.

To get a 1.0.4 version of Autobase, check out/download Liquibase-DSL from
http://github.com/RobertFischer/liquibase-dsl -- run "maker.sh" in the root of that directory. Then
drop the generated "lbdsl.jar" into your Autobase "lib" directory
(./plugins/grails-autobase-0.8.1/lib). Do a "grails clean" and you should be good to go.

~~ Robert Fischer.
Grails Trainining http://GroovyMag.com/training
Smokejumper Consulting http://SmokejumperIT.com
Enfranchised Mind Blog http://EnfranchisedMind.com/blog

Check out my book, "Grails Persistence with GORM and GSQL"!
http://www.smokejumperit.com/redirect.html


karste...@googlemail.com

unread,
Feb 11, 2009, 11:53:37 AM2/11/09
to Autobase
Hi Robert,

I tried that, but now i'm getting the following compile-error:

> <grailsproject>/generated-java-source/Autobase.java:21: package liquibase.parser.groovy does not exist
> import liquibase.parser.groovy.*;
> ^

Kind regards,

Karsten

On 10 Feb., 15:39, Robert Fischer <robert.fisc...@smokejumperit.com>
wrote:
> That's because v0.8.1 is intended for the 1.1 branch, and you're on 1.0.4.  There's a Groovy update
> between the two, which is causing the error you're seeing.
>
> To get a 1.0.4 version of Autobase, check out/download Liquibase-DSL fromhttp://github.com/RobertFischer/liquibase-dsl-- run "maker.sh" in the root of that directory.  Then
> drop the generated "lbdsl.jar" into your Autobase "lib" directory
> (./plugins/grails-autobase-0.8.1/lib).  Do a "grails clean" and you should be good to go.
>
> ~~ Robert Fischer.
> Grails Trainining      http://GroovyMag.com/training
> Smokejumper Consultinghttp://SmokejumperIT.com
> Enfranchised Mind Bloghttp://EnfranchisedMind.com/blog
>
> Check out my book, "Grails Persistence with GORM and GSQL"!http://www.smokejumperit.com/redirect.html
>
> ...
>
> Erfahren Sie mehr »

Robert Fischer

unread,
Feb 11, 2009, 12:16:12 PM2/11/09
to grails-...@googlegroups.com
It's not picking up the generated lbdsl.jar, or the generated lbdsl.jar is empty. I'm afraid that's
a tougher issue to debug than I can do over e-mail.

~~ Robert.
Smokejumper Consulting http://SmokejumperIT.com
Enfranchised Mind Blog http://EnfranchisedMind.com/blog

karste...@googlemail.com

unread,
Feb 12, 2009, 4:14:56 AM2/12/09
to Autobase
Hi Robert,

this seems to be a bug with the download-option of github. I you use
the download button to get a zipped or tared version of the
repository, it only includes the following files in the src-folder
(other folders like eg and lib are completly ignored):

- FindCommand.groovy
- HelloWorldCommand.groovy
- LbdslProperties.groovy
- PrintPerlProperties.groovy


I'll try it again after getting the complete version via directly from
the repository...


Kind regards,

Karsten


On Feb 11, 6:16 pm, Robert Fischer <robert.fisc...@smokejumperit.com>
wrote:
> It's not picking up the generated lbdsl.jar, or the generated lbdsl.jar is empty.  I'm afraid that's
> a tougher issue to debug than I can do over e-mail.
>
> ~~ Robert.
>
> karsten.kr...@googlemail.com wrote:
> > Hi Robert,
>
> > I tried that, but now i'm getting the following compile-error:
>
> >> <grailsproject>/generated-java-source/Autobase.java:21: package liquibase.parser.groovy does not exist
> >> import liquibase.parser.groovy.*;
> >> ^
>
> > Kind regards,
>
> > Karsten
>
> > On 10 Feb., 15:39, Robert Fischer <robert.fisc...@smokejumperit.com>
> > wrote:
> >> That's because v0.8.1 is intended for the 1.1 branch, and you're on 1.0.4.  There's a Groovy update
> >> between the two, which is causing the error you're seeing.
>
> >> To get a 1.0.4 version of Autobase, check out/download Liquibase-DSL fromhttp://github.com/RobertFischer/liquibase-dsl--run "maker.sh" in the root of that directory.  Then
> ...
>
> read more »

Robert Fischer

unread,
Feb 12, 2009, 9:16:02 AM2/12/09
to grails-...@googlegroups.com
Wow. Wouldn't have guess that. It makes me a bit sad to see a GitHub failure like that.

~~ Robert.
Smokejumper Consulting http://SmokejumperIT.com
Enfranchised Mind Blog http://EnfranchisedMind.com/blog

karste...@googlemail.com

unread,
Feb 14, 2009, 9:03:33 PM2/14/09
to Autobase
Hi Robert,

great! With the lbdsl.jar compiled from the sources, Autobase 0.8.2.1
works for Grails 1.0.4 to.
Thanks for your help!

Karsten

On 12 Feb., 15:16, Robert Fischer <robert.fisc...@smokejumperit.com>
wrote:
> Wow.  Wouldn't have guess that.  It makes me a bit sad to see a GitHub failure like that.
>
> ~~ Robert.
>
> ...
>
> Erfahren Sie mehr »

Robert Fischer

unread,
Feb 14, 2009, 9:51:19 PM2/14/09
to grails-...@googlegroups.com
Really? Awesome.

I'll have to release a 0.8.2.2 with 1.0.4 support.

~~ Robert.
Grails Training http://GroovyMag.com/training
Smokejumper Consulting http://SmokejumperIT.com
Enfranchised Mind Blog http://EnfranchisedMind.com/blog
Reply all
Reply to author
Forward
0 new messages