Install Java
Liquibase 3.x requires Java 1.6+ so lets get that installed first
$ sudo yum install java-1.7.0-openjdk
Get the Liquibase Code
I'm just going to install put Liquibase in the home directory for now
$ wget http://sourceforge.net/projects/liquibase/files/Liquibase%20Core/liquibase-3.1.1-bin.tar.gz/download
$ tar zxvf liquibase-3.1.1-bin.tar.gz
$ sudo chmod + x ./liquibase
$ ./liquibase --version
Install Mysql
$ sudo yum install mysql mysql-server
$ sudo chkconfig --levels 235 mysqld on
$ sudo service mysqld start
$ /usr/bin/mysqladmin -u root password 'root'
$ mysql -uroot -proot
Install the Mysql Connector for Java
$ wget http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.30.tar.gz
$ tar zxvf mysql-connector-java-5.1.30.tar.gz
Create the database
$ mysql -uroot -proot
mysql> create database example;
mysql> exit;
Create a Changelog file
$ vim ./changelog.xml
Add the following...
<?xml version="1.0" encoding="UTF-8"?>
<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-3.1.xsd">
<changeSet id="1" author="bob">
<createTable tableName="department">
<column name="id" type="int">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)">
<constraints nullable="false"/>
</column>
<column name="active" type="boolean" defaultValueBoolean="true"/>
</createTable>
</changeSet>
</databaseChangeLog>
Run Liquibase
$ ./liquibase --driver=com.mysql.jdbc.Driver --classpath=mysql-connector-java-5.1.30/mysql-connector-java-5.1.30-bin.jar --changeLogFile=changelog.xml --url="jdbc:mysql://localhost/example" --username=root --password=root update
Create a liquibase.properties file
$ vim ~/liquibase.properties
Add the following...
driver: com.mysql.jdbc.Driver
classpath: mysql-connector-java-5.1.30/mysql-connector-java-5.1.30-bin.jar
url: jdbc:mysql://localhost/example
username: root
password: root
Run Liquibase... with the properties file
$ ./liquibase --changeLogFile=changelog.xml update
No comments:
Post a Comment