<?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; liquibase</title>
	<atom:link href="http://www.wysmedia.com/tag/liquibase/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>Using Liquibase (tutorial)</title>
		<link>http://www.wysmedia.com/2009/02/using-liquibase-tutorial/</link>
		<comments>http://www.wysmedia.com/2009/02/using-liquibase-tutorial/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 02:52:17 +0000</pubDate>
		<dc:creator>adwin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[database migration]]></category>
		<category><![CDATA[liquibase]]></category>

		<guid isPermaLink="false">http://www.wysmedia.comyr.com/?p=27</guid>
		<description><![CDATA[http://www.liquibase.org/manual/]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.liquibase.org">Liquibase</a> is the powerful database migration that available for free. For long time I am envy of rails database migration system. It is nice and have rich features. </p>
<p>Few weeks ago, I found that <a href='http://grails.org'> Grails </a> has Liquibase plugin (there are 2, liquibase and autobase). I tried both plugins and autobase won my heart because the simplicity they offer (not using XML is the biggest advantages, for me at least). Liquibase however build as stand alone java application that you can run with any operating system that support java.</p>
<p> Here I will show you how to configure and using Liquibase on command line, so you can apply whether you are using php, python, or others programming language/framework </p>
<p><span id="more-27"></span></p>
<ul>
<li> First, download and extract Liquibase files from <a href='www.liquibase.org'>www.liquibase.org</a></li>
<li> Create a file named liquibase.properties </li>
<li> Write the following, you can modify it to suit your needs

<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="xml" style="font-family:monospace;">classpath: ../;lib/mysql-connector-java-5.1.6-bin.jar
changeLogFile=changelogs/root.changelog.xml
username=root
password=
url=jdbc:mysql://localhost/tester
driver=com.mysql.jdbc.Driver
logLevel=SEVERE</pre></td></tr></table></div>

<p>* you must download mysql-connector-java-5.xxxx.jar (mysql jdbc driver) from <a href='www.mysql.com'>www.mysql.com</a>
</li>
<li>Create a directory <b>changelogs</b></li>
<li>Inside, create root.changelog.xml and write the following

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;databaseChangeLog</span></span>
<span style="color: #009900;">        <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.liquibase.org/xml/ns/dbchangelog/1.7&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.liquibase.org/xml/ns/dbchangelog/1.7 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.7.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;preConditions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dbms</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;mysql&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sqlCheck</span> <span style="color: #000066;">expectedResult</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>select 1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sqlCheck<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;runningAs</span> <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;root&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/preConditions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;changeSet</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">author</span>=<span style="color: #ff0000;">&quot;nvoxland&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;comment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            You can add comments to changeSets.
            They can even be multiple lines if you would like.
            They aren't used to compute the changeSet MD5Sum, so you can update them whenever you want without causing
            problems.
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/comment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;createTable</span> <span style="color: #000066;">tableName</span>=<span style="color: #ff0000;">&quot;person&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;id&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;int&quot;</span> <span style="color: #000066;">autoIncrement</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constraints</span> <span style="color: #000066;">primaryKey</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">nullable</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/column<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;firstname&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;varchar(50)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;lastname&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;varchar(50)&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constraints</span> <span style="color: #000066;">nullable</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/column<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/createTable<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/changeSet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;changeSet</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">author</span>=<span style="color: #ff0000;">&quot;nvoxland&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;comment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Add a username column so we can use &quot;person&quot; for authentication<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/comment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;addColumn</span> <span style="color: #000066;">tableName</span>=<span style="color: #ff0000;">&quot;person&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;usernae&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;varchar(8)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/addColumn<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/changeSet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;changeSet</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #000066;">author</span>=<span style="color: #ff0000;">&quot;nvoxland&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;comment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Fix misspelled &quot;username&quot; column<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/comment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;renameColumn</span> <span style="color: #000066;">tableName</span>=<span style="color: #ff0000;">&quot;person&quot;</span> <span style="color: #000066;">oldColumnName</span>=<span style="color: #ff0000;">&quot;usernae&quot;</span> <span style="color: #000066;">newColumnName</span>=<span style="color: #ff0000;">&quot;username&quot;</span> <span style="color: #000066;">columnDataType</span>=<span style="color: #ff0000;">&quot;varchar(8)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/changeSet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/databaseChangeLog<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

</li>
<li>When you finished, go to command line and type :<br />
<blockquote><p>java -jar liquibase-1.9.0.jar migrate</p></blockquote>
</li>
<li> This command will create databasechangelog and databasechangeloglock first. Databasechangelog contains record migration that you have done in the past. If you delete one record, next time you run migrate, it will re-run again</li>
</ul>
<p>Now I will explain what is inside the changelog </p>
<p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;databaseChangeLog</span></span>
<span style="color: #009900;">        <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.liquibase.org/xml/ns/dbchangelog/1.7&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.liquibase.org/xml/ns/dbchangelog/1.7 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.7.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;preConditions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dbms</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;mysql&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sqlCheck</span> <span style="color: #000066;">expectedResult</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>select 1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sqlCheck<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;runningAs</span> <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;root&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/preConditions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
..... 
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/databaseChangeLog<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>It is the header of changelog that you need to have.<br />
There are preConditions tag that will help you to know whether the database is mysql or not. </p>
<p>next :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;changeSet</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">author</span>=<span style="color: #ff0000;">&quot;nvoxland&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;comment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            You can add comments to changeSets.
            They can even be multiple lines if you would like.
            They aren't used to compute the changeSet MD5Sum, so you can update them whenever you want without causing
            problems.
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/comment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;createTable</span> <span style="color: #000066;">tableName</span>=<span style="color: #ff0000;">&quot;person&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;id&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;int&quot;</span> <span style="color: #000066;">autoIncrement</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constraints</span> <span style="color: #000066;">primaryKey</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">nullable</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/column<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;firstname&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;varchar(50)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;lastname&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;varchar(50)&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constraints</span> <span style="color: #000066;">nullable</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/column<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/createTable<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/changeSet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>This change set will generate a table Person for you. having column firstname and lastName</p>
<p>next:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;changeSet</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">author</span>=<span style="color: #ff0000;">&quot;nvoxland&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;comment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Add a username column so we can use &quot;person&quot; for authentication<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/comment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;addColumn</span> <span style="color: #000066;">tableName</span>=<span style="color: #ff0000;">&quot;person&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;usernae&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;varchar(8)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/addColumn<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/changeSet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The second update will add &#8220;usernae&#8221; (typo mistakes is on purpose) with width 8 characters</p>
<p>next: we need to fix the usernae become username</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;changeSet</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #000066;">author</span>=<span style="color: #ff0000;">&quot;nvoxland&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;comment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Fix misspelled &quot;username&quot; column<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/comment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;renameColumn</span> <span style="color: #000066;">tableName</span>=<span style="color: #ff0000;">&quot;person&quot;</span> <span style="color: #000066;">oldColumnName</span>=<span style="color: #ff0000;">&quot;usernae&quot;</span> <span style="color: #000066;">newColumnName</span>=<span style="color: #ff0000;">&quot;username&quot;</span> <span style="color: #000066;">columnDataType</span>=<span style="color: #ff0000;">&quot;varchar(8)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/changeSet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

</p>
<p>
They are lots of command that you can use on Liquibase, just make sure you read the manual first on <a href="http://www.liquibase.org/manual/">http://www.liquibase.org/manual/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wysmedia.com/2009/02/using-liquibase-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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 -->
