dropwizard-migrations usage question

989 views
Skip to first unread message

Fredrik Hörte

unread,
Jan 2, 2013, 5:04:49 PM1/2/13
to dropwiz...@googlegroups.com
I am using migrations to keep my database up-to-date so my co-worker and I can have the same database structure and data.

A typical usage scenario is like follows:

1. I do changes to the database in native mysql
2. I run 'mvn clean package' to make sure I can run step 3.
3. I run 'java -jar ... db dump > migrations.xml' to update/replace the migrations.xml file content.
4. I run 'mvn clean package' to include the new migrations.xml file
5. I run 'java -jar ... fast-forward --all' to mark all pending changes as applied.


My question is if there's any smoother way to do this without having to package my project between the migration steps?
Am I using it totally wrong? I am always doing my changes directly in sql and doesn't want to use DDL.

Coda Hale

unread,
Jan 2, 2013, 5:23:53 PM1/2/13
to dropwiz...@googlegroups.com
If you only want to use native SQL, dropwizard-migrations may not help you much.

That said, you don't need to do a whole clean-package cycle in order for your application to be updated. You can use exec:java for a much shorter feedback loop.

---
Coda Hale
http://codahale.com

Fredrik Hörte

unread,
Jan 2, 2013, 5:51:18 PM1/2/13
to dropwiz...@googlegroups.com
Ok, thank you. I'll look into alternatives.

Derek Stainer

unread,
Jan 3, 2013, 3:05:33 PM1/3/13
to dropwiz...@googlegroups.com
Am I misinterpreting this because you can use native SQL with migrations quite easily. We've been doing it for our stuff without any problems. 

Basically you construct change sets only with SQL instead of the XML. You can find more information here if you want: http://www.liquibase.org/manual/formatted_sql_changelogs

That being said I didn't think of using exec:java for a short feedback loop that is a useful suggestion.

Derek

Coda Hale

unread,
Jan 3, 2013, 4:38:51 PM1/3/13
to dropwiz...@googlegroups.com
The way Fredrik described wanting to work (i.e., munge DB, dump DB, commit change sets) didn't sound anything like the way one should use Liquibase (i.e., write change set, test change set, commit change set, deploy change set).

---
Coda Hale
http://codahale.com



Derek Stainer

unread,
Jan 3, 2013, 5:00:04 PM1/3/13
to dropwiz...@googlegroups.com
Do you guys define a single exec:java with the command line args passed via -Dexec.commandLineArgs? Or do you go and simply define the migrate command?

Derek

Fredrik Hörte

unread,
Jan 4, 2013, 2:01:06 AM1/4/13
to dropwiz...@googlegroups.com
This is an example workflow in detail.

1) Using my console (or any MySQL UI) I alter a table adding a column.
2) To get the changes into my migrations.xml file I run "java -jar hello-world.jar db dump helloworld.yml > migrations.xml"
3) Since I need the migrations.xml for doing my fast-forward I run 'mvn clean package' to build the dropwizard jar.
4) To apply (sync) the changes I have done I run java -jar hello-world.jar db fast-forward --all helloworld.yml

If I am using Liquibase wrongly then I'm more than happy to change my workflow. I have just briefly been reading up on their website after I've seen the dropwizard-migrations guide. Also using sql instead of XML makes me happy (http://www.liquibase.org/manual/formatted_sql_changelogs).

Coda Hale

unread,
Jan 4, 2013, 11:11:27 AM1/4/13
to dropwiz...@googlegroups.com
I'd suggest a workflow like the following:

1) Add a change set to migrations.xml.
2) Run db migrate. Check to see that it works.
3) Run db rollback. Check to see that it works.
4) Commit changes.

You can run steps 2 and 3 from your IDE or using man exec:java. There's no need to repackage everything.

Honestly, I'd recommend using Liquibase's refactorings rather than raw SQL. It captures your intent at a high level and allows for the possibility of using an in-memory database like HSQL for unit tests.


--
Coda Hale
http://codahale.com

mgutz

unread,
Jan 8, 2013, 12:07:16 PM1/8/13
to dropwiz...@googlegroups.com
If you like SQL over XML try [1] mybatis migrations. I use the maven plugin in Intellij. The workflow is similar to Coda's.

Reply all
Reply to author
Forward
0 new messages