{"id":1799,"date":"2010-10-12T17:37:31","date_gmt":"2010-10-12T12:07:31","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=1799"},"modified":"2022-01-13T14:04:30","modified_gmt":"2022-01-13T08:34:30","slug":"grails-liquibase-plugin-dbdiff-tool-workaround","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/grails-liquibase-plugin-dbdiff-tool-workaround\/","title":{"rendered":"Grails Liquibase plugin: dbDiff tool workaround"},"content":{"rendered":"<p>The current project I am working on, is going through QA. At the same time development of the new features and bug fixing is on and we couldn&#8217;t afford to loose the test data. So synchronizing the state of the QA database with the development was becoming a pain. So we decided to use grails liquibase plugin.<\/p>\n<p>I found one great article by Jackob Kulzer. As explained by Jackob Kulzer, dbDiff tool in the plugin is hard coded to compare development and test environment databases. The other option available was to write every changeset manually. But I was afraid, what if I forget to update even a single changeset.<\/p>\n<p>I decided to write the script, which would overwrite my test database with the schema of the QA database. QA database was on another server. So I had to write multiple scripts to make it work. But once done it made my job really easy.<\/p>\n<p>Following are the scripts to be created:<\/p>\n<p>1. qaSchemaDump.sh (To be created on the development machine):<\/p>\n<p>[bash]<\/p>\n<p>#SSH to the server and execute generateSchema shell script.<br \/>\n#Note: I had created password less login to the server.<br \/>\nssh amit@qa.myserver.net \/home\/amit\/Scripts\/generateSchema.sh<\/p>\n<p>#Copy QA Database schema to the development machine<br \/>\nscp apg@qa.myserver.net:\/home\/amit\/Scripts\/qaDBSchema.sql \/home\/amit\/Scripts\/liquibase\/qaDBSchema.sql<\/p>\n<p>#Import QA Database schema to test database using createTestDBFromQASchema.sql<br \/>\nmysql -u root &#8211;password=myPassword &amp;lt; \/home\/amit\/Scripts\/liquibase\/createTestDBFromQASchema.sql<br \/>\nexit<\/p>\n<p>[\/bash]<\/p>\n<p>2. generateSchema.sh (To be created on the Server):<\/p>\n<p>[sql]<\/p>\n<p>\/* Creates QA database schema *\/<br \/>\nmysqldump &#8211;no-data &#8211;tables -u root &#8211;password=myPassword myQADatabase &amp;gt; \/home\/amit\/Scripts\/qaDBSchema.sql<\/p>\n<p>[\/sql]<\/p>\n<p>3. createTestDBFromQASchema.sql (To be created on the development machine):<\/p>\n<p>[sql]<br \/>\n\/* drop, create and then use the test database.*\/<br \/>\ndrop database myTestDB; create database myTestDB;<br \/>\nuse myTestDB;<\/p>\n<p>\/*Import the QA database schema to the newly created test database*\/<br \/>\nsource \/home\/amit\/Scripts\/liquibase\/qaDBSchema.sql<br \/>\nexit<\/p>\n<p>[\/sql]<\/p>\n<p>Once all the above mentioned scripts are created, we just need to run &#8216;qaSchemaDump.sh&#8217; and followed by &#8216;grails dbDiff&#8217; and the changeset would be available to us on the console. Then copy this changeset, append it to changeLog.xml and commit it to the repository.<\/p>\n<p>With all this done, login to your QA\/production server, take database <a href=\"http:\/\/www.tothenew.com\/blog\/592\/\">backup<\/a> and now we can run grails migrate-sql to confirm the sql that would be generated and then finally run &#8216;grails migrate&#8217; to update QA\/Production database.<\/p>\n<p>Thanks to Jackob Kulzer and Nathan Voxland (author of the plugin)<\/p>\n<p>Hope this helped!<\/p>\n<p>~~Amit Jain~~<br \/>\namit@intelligrape.com<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"su3I3EX0kE\"><p><a href=\"https:\/\/www.tothenew.com\/blog\/\">Home<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Home&#8221; &#8212; TO THE NEW Blog\" src=\"https:\/\/www.tothenew.com\/blog\/embed\/#?secret=su3I3EX0kE\" data-secret=\"su3I3EX0kE\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The current project I am working on, is going through QA. At the same time development of the new features and bug fixing is on and we couldn&#8217;t afford to loose the test data. So synchronizing the state of the QA database with the development was becoming a pain. So we decided to use grails [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3},"categories":[7],"tags":[4843,422,4840,421],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1799"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=1799"}],"version-history":[{"count":1,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1799\/revisions"}],"predecessor-version":[{"id":54641,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1799\/revisions\/54641"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=1799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=1799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=1799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}