liquibase (http://www.liquibase.org/ ) is a database Refactor tool. This gist is a simple liquibase sample.
- Download your Database JDBC Driver. (e.g. SQLite3 JDBC http://www.liquibase.org/sqlite.html )
- Add the driver name and .jar file to liquibase command line. (e.g.
SQLite3:
liquibase --classpath=sqlitejdbc-v<version>.jar --driver=org.sqlite.JDBC
)
- This simple sample creates 2 tables: MACHINE & MACHINE_STATUS.
- The change log file is
db.change-master.xml
- MACHINE Table
+------------------------------------------------+
| ID [ PK, INTEGER, auto-increments ] |
|================================================|
| MACHINE_NAME [ varchar(255), UNIQUE, INDEX ] |
| HOST_NAME [ varchar(255) ] |
+------------------------------------------------+
- MACHINE_STATUS Table
+---------------------------------+
| MACHINE_ID [ INTEGER ] |
|=================================|
| STATUS [ varchar(255) ] |
+---------------------------------+
- Liquibase command lines documentation: http://www.liquibase.org/documentation/command_line.html
- migration
liquibase --classpath=sqlite-jdbc-3.8.5-pre1.jar --driver=org.sqlite.JDBC --url="jdbc:sqlite:sample.sqlite" migrate
- rollback to change set 1
liquibase --classpath=sqlite-jdbc-3.8.5-pre1.jar --driver=org.sqlite.JDBC --url="jdbc:sqlite:sample.sqlite" rollbackCount 1