I’m fairly new to Liquibase, so I apologize if this is a stupid question, but after experimenting and reading the docs, forums, etc., I’m stuck. Here’s my problem: I think I need to enhance/extend the createTable element to handle additional properties, but I’m having no success accomplishing this. Is this possible?
We’re using Oracle and need better control over table creation syntax than what the core functionality provides. For example, I would like to add a boolean attribute of “parallel” so we can add either “parallel” or “noparallel” to the end of create table statements. There are many other things I would like to specify as well (e.g. params for primary key like initial size, maxextents, pctfree, etc.). I’ve tried accomplishing this using the modifySql functionality, but that raised other issues (i.e. it appended my text to all the comment creation statements from the “remarks” attributes as well).
I know I can get around this by not using the “remarks” tags and using the replace functionality, etc., but by the time I do all of that, it is simpler to have just used a “sql” tag and written the SQL by hand. There are other tags I’d like to extend in similar ways as well. Also, I know I could just re-implement the createTable functionality within my own change tag, but that seems silly - I just need to extend it.
Is it possible to accomplish what I’m trying to do? Can someone point me in the right direction? All of the tutorials I’ve found seem to deal with implementing new change tags, not extending existing tags.
Originally posted by: rowens
I'm fairly new to Liquibase, so I apologize if this is a stupid question, but after experimenting and reading the docs, forums, etc., I'm stuck. Here's my problem: I think I need to enhance/extend the createTable element to handle additional properties, but I'm having no success accomplishing this. Is this possible?
I do this like so (for MySQL):
You could probably come up with something for Oracle.
Thanks for the reply. I agree that I can do what you are suggesting, but it is (slightly) more complex than that. One issue arises since the createTable change results in more than one SQL statement. For example, if I have a change like this:
This results in three SQL statements:
CREATE TABLE mytable (myKey numeric) TABLESPACE DATA;
COMMENT ON TABLE mytable IS ‘A description of my table’;
COMMENT ON COLUMN mytable.myKey IS ‘A description of my column’;
If I use the append strategy, my extra parameters get appended to all three SQL statements, which makes the comment statements invalid. Instead, what I have to do is use replace and replace “TABLESPACE DATA” with “TABLESPACE DATA NOLOGGING NOPARALLEL” (for example). That strategy works, but it is not very elegant. It requires that I know exactly how the create table SQL statement will end so I can match to it and it requires that whatever I’m using for my replace argument doesn’t appear anywhere else in the generated SQL.
So yes, I can make that strategy work, but I’m looking for something more straightforward. Also, my goal is to push my development team to adopt Liquibase, so trying to explain how to make this replace strategy work to both on-shore and off-shore team members is not very appealing.
Again, thanks for the reply, but I’m hoping a better solution exists.
The ability to extend and enhance the built in changes, and add new ones is new with the upcoming 2.0 release. See http://liquibase.org/extensions for more info. The idea is that the core liquibase library does not need to understand or support an “engine” attribute on createTable, but a mysql extension would. There is currently a fairly extensive oracle extension and a beginning sqlserver and postgres extension. A mysql extension would be very good to add as well. Take a look at the oracle extension and see if it already adds what you need. If not, you should be able to use it as a starting point. And feel free to provide improvements back to the oracle extension if you like/can :)
The extension framework is actually very powerful, and hopefully easy enough to use to allow anyone to get liquibase to work with their custom needs.
Nathan
Thanks for your response here. I know it is very old thread, but I cam across the same issue. I think it is same as mentioned on https://liquibase.jira.com/browse/CORE-491 as well. It is great that we have “extensions” to our rescue but still, is the fix to original issue planned or already fixed?