Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liquibase XML generator

Is there opensource/free liquibase (http://www.liquibase.org) xml generator?

Alternative to "Power Architect and Liquibase combo". Where can I create database model and then transform it to Liquibase XML format or transform pure sql to Liquibase XML?

like image 642
Jiro Matchonson Avatar asked Jun 12 '13 10:06

Jiro Matchonson


1 Answers

There isn't any available generator since I know.

Actually you can do it by your own by using liquibase core classes.

An example of use:

// .. imports

// create a changelog
liquibase.changelog.DatabaseChangeLog databaseChangeLog = new liquibase.changelog.DatabaseChangeLog();

// create a changeset
liquibase.changelog.ChangeSet changeSet = new liquibase.changelog.ChangeSet("1", "prates", false, false, "", null, null, true, null, databaseChangeLog);

// create a drop table change
liquibase.change.core.DropTableChange dropTableChange = new liquibase.change.core.DropTableChange();

dropTableChange.setTableName("person");

changeSet.addChange(dropTableChange);

// add created changeset to changelog
databaseChangeLog.addChangeSet(changeSet);

// create a new serializer
XMLChangeLogSerializer xmlChangeLogSerializer = new XMLChangeLogSerializer();

String output = null;

ByteArrayOutputStream baos = new ByteArrayOutputStream();

xmlChangeLogSerializer.write(databaseChangeLog.getChangeSets(), baos);

output = baos.toString();

// print output
System.out.println(output);
like image 71
rodrigocprates Avatar answered Oct 01 '22 14:10

rodrigocprates