Permalink
Browse files

Json and Yaml changelog parse support generally works

  • Loading branch information...
1 parent 2da7a69 commit 6bd0baed78400522ea737034bf05c0e64c6f78ba @nvoxland nvoxland committed Mar 18, 2013
Showing with 2,911 additions and 41 deletions.
  1. +10 −0 liquibase-core/src/main/java/liquibase/change/ChangeParameterMetaData.java
  2. +1 −1 liquibase-core/src/main/java/liquibase/change/ChangeWithColumns.java
  3. +4 −4 liquibase-core/src/main/java/liquibase/change/core/AddColumnChange.java
  4. +4 −4 liquibase-core/src/main/java/liquibase/change/core/CreateIndexChange.java
  5. +4 −4 liquibase-core/src/main/java/liquibase/change/core/CreateTableChange.java
  6. +2 −2 liquibase-core/src/main/java/liquibase/change/core/InsertDataChange.java
  7. +10 −1 liquibase-core/src/main/java/liquibase/change/core/LoadDataChange.java
  8. +5 −6 liquibase-core/src/main/java/liquibase/change/core/RawSQLChange.java
  9. +4 −4 liquibase-core/src/main/java/liquibase/change/core/UpdateDataChange.java
  10. +12 −0 liquibase-core/src/main/java/liquibase/parser/core/json/JsonChangeLogParser.java
  11. +4 −5 liquibase-core/src/main/java/liquibase/parser/core/xml/XMLChangeLogSAXHandler.java
  12. +410 −0 liquibase-core/src/main/java/liquibase/parser/core/yaml/YamlChangeLogParser.java
  13. +1 −0 liquibase-core/src/main/java/liquibase/precondition/Precondition.java
  14. +34 −0 liquibase-core/src/main/java/liquibase/serializer/core/json/JsonChangeLogSerializer.java
  15. +1 −1 liquibase-core/src/main/java/liquibase/serializer/core/xml/XMLChangeLogSerializer.java
  16. +192 −0 liquibase-core/src/main/java/liquibase/serializer/core/yaml/YamlChangeLogSerializer.java
  17. +4 −0 liquibase-core/src/main/java/liquibase/statement/SequenceNextValueFunction.java
  18. +8 −8 liquibase-core/src/test/java/liquibase/change/core/AddColumnChangeTest.java
  19. +53 −0 liquibase-core/src/test/java/liquibase/parser/core/yaml/YamlChangeLogParserTest.java
  20. +41 −0 liquibase-core/src/test/java/liquibase/serializer/core/yaml/YamlChangeLogSerializerTest.java
  21. +1 −1 liquibase-core/src/test/java/liquibase/sqlgenerator/core/CreateTableGeneratorTest.java
  22. +44 −0 liquibase-integration-tests/src/test/java/liquibase/dbtest/h2/H2IntegrationTest.java
  23. +1,178 −0 liquibase-integration-tests/src/test/resources/changelogs/json/common.tests.changelog.json
  24. +119 −0 liquibase-integration-tests/src/test/resources/changelogs/json/rollback.tests.changelog.json
  25. +9 −0 liquibase-integration-tests/src/test/resources/changelogs/json/rollbackinclude/createTables.sql
  26. +2 −0 liquibase-integration-tests/src/test/resources/changelogs/json/rollbackinclude/rollbackTables.sql
  27. +624 −0 liquibase-integration-tests/src/test/resources/changelogs/yaml/common.tests.changelog.yaml
  28. +119 −0 liquibase-integration-tests/src/test/resources/changelogs/yaml/rollback.tests.changelog.yaml
  29. +9 −0 liquibase-integration-tests/src/test/resources/changelogs/yaml/rollbackinclude/createTables.sql
  30. +2 −0 liquibase-integration-tests/src/test/resources/changelogs/yaml/rollbackinclude/rollbackTables.sql
@@ -137,6 +137,8 @@ public void setValue(Change change, Object value) {
try {
if (dataType.equals("bigInteger")) {
value = new BigInteger((String) value);
+ } else if (dataType.equals("databaseFunction")) {
+ value = new DatabaseFunction((String) value);
} else {
throw new UnexpectedLiquibaseException("Unknown Data Type: "+dataType);
}
@@ -152,6 +154,14 @@ public void setValue(Change change, Object value) {
if (writeMethod == null) {
throw new UnexpectedLiquibaseException("Could not find writeMethod for "+this.parameterName);
}
+ Class<?> expectedWriteType = writeMethod.getParameterTypes()[0];
+ if (value != null && !expectedWriteType.isAssignableFrom(value.getClass())) {
+ if (expectedWriteType.equals(String.class)) {
+ value = value.toString();
+ } else {
+ throw new UnexpectedLiquibaseException("Could not convert "+value.getClass().getName()+" to "+expectedWriteType.getName());
+ }
+ }
writeMethod.invoke(change, value);
}
}
@@ -15,6 +15,6 @@
/**
* Return all the {@link ColumnConfig} objects defined for this {@link Change }
*/
- public List<T> getColumn();
+ public List<T> getColumns();
}
@@ -60,11 +60,11 @@ public void setTableName(String tableName) {
}
@DatabaseChangeProperty(requiredForDatabase = "all", description = "Column constraint and foreign key information. Setting the \"defaultValue\" attribute will specify a default value for the column. Setting the \"value\" attribute will set all rows existing to the specified value without modifying the column default.")
- public List<ColumnConfig> getColumn() {
+ public List<ColumnConfig> getColumns() {
return column;
}
- public void setColumn(List<ColumnConfig> column) {
+ public void setColumns(List<ColumnConfig> column) {
this.column = column;
}
@@ -89,7 +89,7 @@ public ValidationErrors validate(Database database) {
List<SqlStatement> sql = new ArrayList<SqlStatement>();
- for (ColumnConfig column : getColumn()) {
+ for (ColumnConfig column : getColumns()) {
Set<ColumnConstraint> constraints = new HashSet<ColumnConstraint>();
ConstraintsConfig constraintsConfig =column.getConstraints();
if (constraintsConfig != null) {
@@ -134,7 +134,7 @@ public ValidationErrors validate(Database database) {
}
}
- for (ColumnConfig column : getColumn()) {
+ for (ColumnConfig column : getColumns()) {
String columnRemarks = StringUtils.trimToNull(column.getRemarks());
if (columnRemarks != null) {
SetColumnRemarksStatement remarksStatement = new SetColumnRemarksStatement(catalogName, schemaName, tableName, column.getName(), columnRemarks);
@@ -59,14 +59,14 @@ public void setTableName(String tableName) {
}
@DatabaseChangeProperty(requiredForDatabase = "all", mustEqualExisting = "index.column", description = "Column(s) to add to the index")
- public List<ColumnConfig> getColumn() {
+ public List<ColumnConfig> getColumns() {
if (columns == null) {
return new ArrayList<ColumnConfig>();
}
return columns;
}
- public void setColumn(List<ColumnConfig> columns) {
+ public void setColumns(List<ColumnConfig> columns) {
this.columns = columns;
}
@@ -86,7 +86,7 @@ public void setTablespace(String tablespace) {
public SqlStatement[] generateStatements(Database database) {
List<String> columns = new ArrayList<String>();
- for (ColumnConfig column : getColumn()) {
+ for (ColumnConfig column : getColumns()) {
columns.add(column.getName());
}
@@ -98,7 +98,7 @@ public void setTablespace(String tablespace) {
getTableName(),
this.isUnique(),
getAssociatedWith(),
- columns.toArray(new String[getColumn().size()]))
+ columns.toArray(new String[getColumns().size()]))
.setTablespace(getTablespace())
};
}
@@ -52,7 +52,7 @@ public ValidationErrors validate(Database database) {
public SqlStatement[] generateStatements(Database database) {
CreateTableStatement statement = new CreateTableStatement(getCatalogName(), getSchemaName(), getTableName());
- for (ColumnConfig column : getColumn()) {
+ for (ColumnConfig column : getColumns()) {
ConstraintsConfig constraints = column.getConstraints();
boolean isAutoIncrement = column.isAutoIncrement() != null && column.isAutoIncrement();
@@ -111,7 +111,7 @@ public ValidationErrors validate(Database database) {
}
}
- for (ColumnConfig column : getColumn()) {
+ for (ColumnConfig column : getColumns()) {
String columnRemarks = StringUtils.trimToNull(column.getRemarks());
if (columnRemarks != null) {
SetColumnRemarksStatement remarksStatement = new SetColumnRemarksStatement(catalogName, schemaName, tableName, column.getName(), columnRemarks);
@@ -137,14 +137,14 @@ public ValidationErrors validate(Database database) {
}
@DatabaseChangeProperty(requiredForDatabase = "all")
- public List<ColumnConfig> getColumn() {
+ public List<ColumnConfig> getColumns() {
if (columns == null) {
return new ArrayList<ColumnConfig>();
}
return columns;
}
- public void setColumn(List<ColumnConfig> columns) {
+ public void setColumns(List<ColumnConfig> columns) {
this.columns = columns;
}
@@ -52,11 +52,11 @@ public void setTableName(String tableName) {
}
@DatabaseChangeProperty(requiredForDatabase = "all", mustEqualExisting = "table.column", description = "Data to insert into columns")
- public List<ColumnConfig> getColumn() {
+ public List<ColumnConfig> getColumns() {
return columns;
}
- public void setColumn(List<ColumnConfig> columns) {
+ public void setColumns(List<ColumnConfig> columns) {
this.columns = columns;
}
@@ -3,6 +3,7 @@
import liquibase.change.*;
import liquibase.database.Database;
import liquibase.exception.UnexpectedLiquibaseException;
+import liquibase.exception.Warnings;
import liquibase.logging.LogFactory;
import liquibase.logging.Logger;
import liquibase.resource.ResourceAccessor;
@@ -98,6 +99,9 @@ public String getSeparator() {
}
public void setSeparator(String separator) {
+ if (separator.equals("\\t")) {
+ separator = "\t";
+ }
this.separator = separator;
}
@@ -114,7 +118,7 @@ public void addColumn(LoadDataColumnConfig column) {
}
@DatabaseChangeProperty(description = "Defines how the data should be loaded.")
- public List<LoadDataColumnConfig> getColumn() {
+ public List<LoadDataColumnConfig> getColumns() {
return columns;
}
@@ -282,4 +286,9 @@ public CheckSum generateCheckSum() {
}
}
}
+
+ @Override
+ public Warnings warn(Database database) {
+ return null;
+ }
}
@@ -3,7 +3,6 @@
import liquibase.change.AbstractSQLChange;
import liquibase.change.DatabaseChange;
import liquibase.change.ChangeMetaData;
-import liquibase.change.DatabaseChangeProperty;
/**
* Allows execution of arbitrary SQL. This change can be used when existing changes are either don't exist,
@@ -24,7 +23,7 @@
priority = ChangeMetaData.PRIORITY_DEFAULT)
public class RawSQLChange extends AbstractSQLChange {
- private String comments;
+ private String comment;
public RawSQLChange() {
}
@@ -33,12 +32,12 @@ public RawSQLChange(String sql) {
setSql(sql);
}
- public String getComments() {
- return comments;
+ public String getComment() {
+ return comment;
}
- public void setComments(String comments) {
- this.comments = comments;
+ public void setComment(String comment) {
+ this.comment = comment;
}
public String getConfirmationMessage() {
@@ -19,11 +19,11 @@ public UpdateDataChange() {
}
@DatabaseChangeProperty(requiredForDatabase = "all", description = "Data to update")
- public List<ColumnConfig> getColumn() {
+ public List<ColumnConfig> getColumns() {
return columns;
}
- public void setColumn(List<ColumnConfig> columns) {
+ public void setColumns(List<ColumnConfig> columns) {
this.columns = columns;
}
@@ -38,7 +38,7 @@ public void removeColumn(ColumnConfig column) {
public SqlStatement[] generateStatements(Database database) {
boolean needsPreparedStatement = false;
- for (ColumnConfig column : getColumn()) {
+ for (ColumnConfig column : getColumns()) {
if (column.getValueBlobFile() != null) {
needsPreparedStatement = true;
}
@@ -55,7 +55,7 @@ public void removeColumn(ColumnConfig column) {
UpdateStatement statement = new UpdateStatement(getCatalogName(), getSchemaName(), getTableName());
- for (ColumnConfig column : getColumn()) {
+ for (ColumnConfig column : getColumns()) {
statement.addNewColumnValue(column.getName(), column.getValueObject());
}
@@ -0,0 +1,12 @@
+package liquibase.parser.core.json;
+
+import liquibase.parser.core.yaml.YamlChangeLogParser;
+import liquibase.resource.ResourceAccessor;
+
+public class JsonChangeLogParser extends YamlChangeLogParser {
+
+ @Override
+ public boolean supports(String changeLogFile, ResourceAccessor resourceAccessor) {
+ return changeLogFile.endsWith(".json");
+ }
+}
@@ -21,7 +21,6 @@
import liquibase.change.core.AbstractModifyDataChange;
import liquibase.change.core.CreateProcedureChange;
import liquibase.change.core.CreateViewChange;
-import liquibase.change.core.DeleteDataChange;
import liquibase.change.core.ExecuteShellCommandChange;
import liquibase.change.core.InsertDataChange;
import liquibase.change.core.LoadDataChange;
@@ -413,7 +412,7 @@ else if (change != null && "constraints".equals(qName)) {
}
ColumnConfig lastColumn = null;
if (change instanceof ChangeWithColumns) {
- List<ColumnConfig> columns = ((ChangeWithColumns) change).getColumn();
+ List<ColumnConfig> columns = ((ChangeWithColumns) change).getColumns();
if (columns != null && columns.size() > 0) {
lastColumn = columns.get(columns.size() - 1);
}
@@ -605,7 +604,7 @@ public void endElement(String uri, String localName, String qName)
inRollback = false;
} else if (change != null && change instanceof RawSQLChange
&& "comment".equals(qName)) {
- ((RawSQLChange) change).setComments(textString);
+ ((RawSQLChange) change).setComment(textString);
text = new StringBuffer();
} else if (change != null && "where".equals(qName)) {
if (change instanceof AbstractModifyDataChange) {
@@ -634,10 +633,10 @@ public void endElement(String uri, String localName, String qName)
} else if (change != null && qName.equals("column")
&& textString != null) {
if (change instanceof InsertDataChange) {
- List<ColumnConfig> columns = ((InsertDataChange) change).getColumn();
+ List<ColumnConfig> columns = ((InsertDataChange) change).getColumns();
columns.get(columns.size() - 1).setValue(textString);
} else if (change instanceof UpdateDataChange) {
- List<ColumnConfig> columns = ((UpdateDataChange) change).getColumn();
+ List<ColumnConfig> columns = ((UpdateDataChange) change).getColumns();
columns.get(columns.size() - 1).setValue(textString);
} else {
throw new RuntimeException("Unexpected column with text: " + textString);
Oops, something went wrong.

0 comments on commit 6bd0bae

Please sign in to comment.