autobase failed to update boolean

3 views
Skip to first unread message

Adwin Wijaya

unread,
Dec 27, 2008, 1:02:55 AM12/27/08
to Autobase
Hi,

I found this bug on autobase plugins (grails plugin), but I have no
idea where i should post this ..

i have a table master which has boolean field. so I did this to make
sure that all current field in taxable mode.

update(tableName:"master"){
column(name:"is_taxable", value:true)
}

if it compiled and running it will produce : update table master set
is_taxable='true' --> it should be is_taxable=true


another question,

in one changeset can we add checking such as
if(master.is_tax-able){
dropColumn(tablename:"master", columnName:"is_tax-able");
}

or ignore the changes instead of producing error and stop working :)


regards
adwin

Robert Fischer

unread,
Dec 27, 2008, 9:45:27 AM12/27/08
to grails-...@googlegroups.com
For the first part, this is due to a limitation on the XML side of things, you have to use
"valueBoolean" to specify a boolean value for a column.
http://www.liquibase.org/manual/column#available_attributes

The "value" column is passed with single-quotes, which means it works for Strings and, depending on
your database, might work for dates or numbers given proper formatting. It almost certainly won't
work for booleans, though, as you've discovered.

It may be worth doing some type checking to make "value" a bit more magical, but there's a lot of
issues to discuss around that. Feel free to create a JIRA for that with the behavior you'd expect:
http://jira.codehaus.org/browse/GRAILSPLUGINS/component/13540

For the second part --

The Groovy code "master.is_tax-able" isn't valid -- you can't have hyphens in bare property
accesses. And since I don't know what "master" is declared as, I'm not sure what the code means.

If what you mean is to check if the 'master' table has a 'is_taxable' column, then that can be done
through preConditions.

changeSet(...) {
preConditions {
columnExists(tableName:'master', columnName:'is_taxable')
}

// Implement changes below here
}

More info on those at the Liquibase manual: http://www.liquibase.org/manual/preconditions

I'm pretty resistant to building a more Groovy-esque metadata querying structure, mainly because
it's a lot of work for (in my view) little value. If you'd like to fork the project in GitHub and
implement such a beast, I'd be very open to folding it back into the main project when you're done.

~~ Robert.
--
~~ Robert Fischer.
Grails Trainining http://www.smokejumperit.com/grails_training.html
Smokejumper Consulting http://smokejumperit.com
Enfranchised Mind Blog http://enfranchisedmind.com/blog

Adwin Wijaya

unread,
Dec 29, 2008, 10:54:05 PM12/29/08
to Autobase
Thank you Robert, now i understand about that.

btw, when autobase migration will be executed ? is it before bootstrap
or after bootstrap ?

also, if i added new fields on my domain, is autobase executed first
or after domain compiled (and the table modified) ?
for example:

domain :
class Book {
Author author
String ISBN ;
BigDecimal price ;
Integer edition ; // i add this field
}

when autobase migration executed, did autobase recognized Book.edition
field ?
I haven't tried it .. it just come up on my mind when i type this
email :)

thanks a lot.


On Dec 27, 9:45 pm, Robert Fischer <robert.fisc...@smokejumperit.com>
wrote:
> For the first part, this is due to a limitation on the XML side of things, you have to use
> "valueBoolean" to specify a boolean value for a column.http://www.liquibase.org/manual/column#available_attributes

Robert Fischer

unread,
Dec 29, 2008, 11:13:20 PM12/29/08
to grails-...@googlegroups.com
It executes before bootstrap, but after the table modifications.

Adwin Wijaya

unread,
Jan 1, 2009, 3:43:21 AM1/1/09
to Autobase
HI Robert,

I tried this on my db but it seems the preconditions was ignored thus
it produce exception error while trying to drop/rename column

here is my migrations script (for mysql db)

changeSet(id:'ChangeFoo', author:'R61') {
def tableName = "Foo";
def oldColumnName= "test";
def newColumnName= "no_test";

preConditions(){
columnExists(schemaName:'grailstest', tableName:'Foo',
columnName:'test')
}

dropColumn(tableName: tableName, columnName:newColumnName);
renameColumn(tableName:tableName, oldColumnName:oldColumnName,
newColumnName:newColumnName, columnDataType:"int");
}


error :
[6812] AutobaseGrailsPlugin Error during Autobase migration
liquibase.exception.MigrationFailedException: Migration failed for
change set te
ster-autobase::ChangeFoo::R61:
Reason: liquibase.exception.JDBCException: Error executing SQL
ALTER TABLE
`Foo` CHANGE `test` `no_test` int:
Caused By: Error executing SQL ALTER TABLE `Foo` CHANGE
`test` `no_tes
t` int:
Caused By: Unknown column 'test' in 'foo'
at liquibase.ChangeSet.execute(ChangeSet.java:227)
at liquibase.parser.visitor.UpdateVisitor.visit
(UpdateVisitor.java:26)
at liquibase.parser.ChangeLogIterator.run
(ChangeLogIterator.java:41)
at liquibase.LiquibaseDsl.update(LiquibaseDsl.groovy:93)
at Autobase.migrate(Autobase.groovy:41)
at AutobaseGrailsPlugin$__clinit__closure7.doCall
(AutobaseGrailsPlugin.g
roovy:50)
at AutobaseGrailsPlugin.invokeMethod
(AutobaseGrailsPlugin.groovy)
at AutobaseGrailsPlugin$_closure2.doCall
(AutobaseGrailsPlugin.groovy:82)
.....
===========================================================================================

my domain has no "test" field .. I just want to test wheter the
preconditions working or not.

is there any mistakes on preConditions ?

thanks

regards
adwin

On Dec 30 2008, 11:13 am, Robert Fischer
Reply all
Reply to author
Forward
0 new messages