<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Wysmedia.com &#187; migration</title>
	<atom:link href="http://www.wysmedia.com/tag/migration/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wysmedia.com</link>
	<description>~ We make IT easy for you ~</description>
	<lastBuildDate>Fri, 08 May 2009 07:02:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Autobase plugins</title>
		<link>http://www.wysmedia.com/2009/02/autobase-plugins/</link>
		<comments>http://www.wysmedia.com/2009/02/autobase-plugins/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 16:47:33 +0000</pubDate>
		<dc:creator>adwin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[autobase]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[liquibase]]></category>
		<category><![CDATA[migration]]></category>

		<guid isPermaLink="false">http://www.wysmedia.comyr.com/?p=4</guid>
		<description><![CDATA[Sometimes, we need to refactor our domain / database table.  For example, our first domain looks like this :

1
2
3
4
class Person &#123;
String personName ;
BigDecimal monthlyIncome ;
&#125;

Now we want to eliminate/change the monthlyIncome and replace it with  BigDecimal weeklyIncome
we type

1
2
3
4
class Person &#123;
String personName ;
BigDecimal weeklyIncome;
&#125;

But, when we look at the table, it still have monthlyIncome field. [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, we need to refactor our domain / database table.  For example, our first domain looks like this :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Person <span style="color: #66cc66;">&#123;</span>
<span style="color: #aaaadd; font-weight: bold;">String</span> personName <span style="color: #66cc66;">;</span>
<span style="color: #aaaadd; font-weight: bold;">BigDecimal</span> monthlyIncome <span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Now we want to eliminate/change the monthlyIncome and replace it with  <code>BigDecimal weeklyIncome</code></p>
<p>we type</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Person <span style="color: #66cc66;">&#123;</span>
<span style="color: #aaaadd; font-weight: bold;">String</span> personName <span style="color: #66cc66;">;</span>
<span style="color: #aaaadd; font-weight: bold;">BigDecimal</span> weeklyIncome<span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>But, when we look at the table, it still have monthlyIncome field. That&#8217;s why we need to eliminate it. If we works as a team, this could be a messy and troublesome, because <code>monthlyIncome</code> is not nullable. So it produce error (JDBC errors) when someone tried to update or save into that table.</p>
<p>That&#8217;s why we need Autobase for this dirty job. Autobase is Grails plugin that created base on <a href="http://www.liquibase.org">Liquibase</a>. Liquibase, however using xml format to do <em>database migration</em>. I hate to write on xml actually.<br />
Luckily, <a href="http://wiki.github.com/RobertFischer/autobase">Robert Fischer</a>, wrote this useful Grails&#8217;s plugin, so that we can write it using Groovy DSL.<br />
<span id="more-4"></span></p>
<p>Here is the steps we need to make:</p>
<ol>
<li>command line: grails install-plugin autobase. This command willl install autobase plugin into your project. You can download manually from <a href="http://plugins.grails.org">http://plugins.grails.org</a></li>
<li>command line: grails create-migration Person, this will produce migration script under migrations/computerName/PersonMigration.groovy</li>
<li>write this inside PersonMigration.groovy

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;">changeSet<span style="color: #66cc66;">&#40;</span>id:<span style="color: #ff0000;">'PersonMigration-1'</span>, author:<span style="color: #ff0000;">'R61'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
preConditions<span style="color: #66cc66;">&#123;</span>
columnExists<span style="color: #66cc66;">&#40;</span>tableName:<span style="color: #ff0000;">&quot;person&quot;</span>, columnName:<span style="color: #ff0000;">&quot;monthly_income&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
comment<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;remove monthly_income from person table&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
sql<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;alter table person drop monthly_income&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

</li>
<li>Re run your grails and this script will be executed.</li>
</ol>
<p>For more details about the syntax that you can have inside migration file, try to read the documentation at <a href="http://www.liquibase.org/manual/">liquibase manual</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wysmedia.com/2009/02/autobase-plugins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->
