Using YAML, JSON or SQL for migrations?

1,949 views
Skip to first unread message

Eric Fenderbosch

unread,
Jul 19, 2013, 9:19:12 AM7/19/13
to dropwiz...@googlegroups.com
Liquidbase supports these other formats, are there any plans to support them in Dropwizard?

Eric Fenderbosch

unread,
Jul 19, 2013, 9:43:12 AM7/19/13
to dropwiz...@googlegroups.com
This could be done pretty easily by adding a migration file property to DatabaseConfiguration and then use that property in ManagedLiquibase's constructor.

Eric Fenderbosch

unread,
Jul 19, 2013, 10:02:32 AM7/19/13
to dropwiz...@googlegroups.com
It looks like master (0.7.x ?) on github now supports this option, although it isn't exactly clear how to use it. Any idea on a release date?

I was going to fork, but the code doesn't match up with the current release of 0.6.2.

Derek Stainer

unread,
Jul 19, 2013, 2:23:54 PM7/19/13
to dropwiz...@googlegroups.com
If I recall correctly you can reference any format from migrations.xml as a include entry. We did this with the SQL format.

For example:

<databaseChangeLog
       
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
       
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
         http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd"
>


   
<include file="my_migration_script.sql" relativeToChangelogFile="true"/>

</databaseChangeLog>


That being said, we chose to go SQL, there is another entry on this list where Coda recommends going the XML approach (https://groups.google.com/d/msg/dropwizard-user/wRvbQWJGN3s/GIh2StNEUqEJ) take a look at that to see if that does impact you.

Derek

Eric Fenderbosch

unread,
Jul 19, 2013, 2:51:39 PM7/19/13
to dropwiz...@googlegroups.com
I tried importing an SQL file and it treated it like XML and the parser barfed.

I got it working this way:

<changeSet id="1" author="eric.fenderbosch">
<sql>
<![CDATA[
create table click (
id bigserial primary key,
ip inet not null,
created_at timestamp default current_timestamp
);
]]>
</sql>
<rollback>drop table click</rollback>
</changeSet>

Nick Telford

unread,
Jul 19, 2013, 3:30:33 PM7/19/13
to dropwiz...@googlegroups.com
0.7.0-SNAPSHOT includes the ability to specify a different migrations file on the command-line, when you invoke any of the Liquibase Commands, using the --migrations-file=<file> parameter.

I strongly recommend using the XML migrations as they're the only migrations that are reversible (via rollbacks). They're also more portable than the SQL format, which is database specific.

Eric Fenderbosch

unread,
Jul 19, 2013, 5:06:07 PM7/19/13
to dropwiz...@googlegroups.com
XML is buggy and won't create a timestamp with default value of current_timestamp correctly. It puts quotes around 'current_timestamp' and Postgres complains about the syntax.

Nathan Fisher

unread,
Jul 19, 2013, 7:01:01 PM7/19/13
to dropwiz...@googlegroups.com
Hi Eric,

I prefer SQL to XML.  The way I've configured it for my apps is placing the XML below in src/main/resources/migrations.xml. All of your migrations can then be placed in src/main/resources/migrations/. I wrote an article on my experience with dropwizard and migrations here; http://junctionbox.ca/2013/05/10/dropwizard-liquibase-migrations/

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
 
xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9"
 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd">
   
<includeAll path="migrations"/>
</databaseChangeLog>

Kind Regards,
Nathan

Eric Fenderbosch

unread,
Jul 19, 2013, 9:01:19 PM7/19/13
to dropwiz...@googlegroups.com
I really like that solution Nathan. Thanks. I'll give it a try Monday morning.

Eric Fenderbosch

unread,
Jul 22, 2013, 9:44:18 AM7/22/13
to dropwiz...@googlegroups.com
It doesn't seem to find my SQL files. I've manually dropped my table and deleted from databasechangelog.


mvn liquibase:status
[INFO] Scanning for projects...
[INFO]                                                                        
[INFO] ------------------------------------------------------------------------
[INFO] Building post-delivery-tracking-service 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- liquibase-maven-plugin:2.0.5:status (default-cli) @ post-delivery-tracking-service ---
[INFO] ------------------------------------------------------------------------
[INFO] Executing on Database: jdbc:postgresql:test
INFO
7/22/13 9:41 AM:liquibase: Reading from databasechangelog
postgres@jdbc
:postgresql:test is up to date
INFO
7/22/13 9:41 AM:liquibase: Successfully released change log lock
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.038s
[INFO] Finished at: Mon Jul 22 09:41:24 EDT 2013
[INFO] Final Memory: 13M/145M
[INFO] ------------------------------------------------------------------------

Graham O'Regan

unread,
Jul 22, 2013, 10:14:43 AM7/22/13
to dropwiz...@googlegroups.com
are you using maven for your build? if so, check that the sql files exist under target/classes/migrations and that your migrations.xml is under target/classes.


--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-us...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages