Managing and applying database changes with LiquiBase
LiquiBase is an open source, DBMS-independent library for tracking, managing and applying database changes. It is built on a simple premise: All database changes (structure and data) are stored in an XML-based descriptive manner and checked into source control.
Adding a changeset
<?xml version="1.0" encoding="UTF-8"?> <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.6 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.6.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" defaultValue="1"/> </createTable> </changeSet> </databaseChangeLog>
Running the ChangeSet
There are many ways to execute your change log including via command line, Ant, Maven, Grails, etc.
liquibase --driver=com.mysql.jdbc.Driver \ --classpath=/path/to/classes \ --changeLogFile=com/example/db.changelog.xml \ --url="jdbc:mysql://localhost/example" \ --username=user \ --password=asdf \ migrate
Done!
You will see that your database now contains a table called “department”. Two other tables are created as well: “databasechangelog” and “databasechangeloglock”. The databasechangelog table contains a list of all the statements that have been run against the database. The databasechangeloglock table is used to make sure two machines don’t attempt to modify the database at the same time.
What is the advantage over keeping a file with SQL statements that updates the database?
Karsten Silz
May 21, 2008 at 1:20 pm
* Increased agility and lower risk to business critical operations
* Higher transaction throughput and faster batch processing
* Increased developer productivity
* Easier database maintenance
* Simpler system integration
* More scalable and reliable systems
* Improved transactional security
fedecarg
May 21, 2008 at 1:55 pm
[...] Bundle – May 21 Author : Jonathan Franzone No Comments Managing and applying database changes with LiquiBase Federico Cargnelutti gives a quick demonstration of how to use LiquiBase, an open source, [...]
Link Bundle - May 21 | franzone.com
May 21, 2008 at 3:36 pm