Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

CORE-1032

Metdata comment syntax for Formatted SQL Changelogs are not valid comments in MySQL

from pull request #39
  • Loading branch information...
commit 0bfa3932d45dbcf7b9ace1b20aaf1a04d5e7411f 1 parent 6b7f597
@nvoxland nvoxland authored
View
2  liquibase-core/src/main/java/liquibase/database/core/MySQLDatabase.java
@@ -60,7 +60,7 @@ public String getCurrentDateTimeFunction() {
@Override
public String getLineComment() {
- return "--";
+ return "-- ";
}
@Override
View
22 ...se-core/src/main/java/liquibase/parser/core/formattedsql/FormattedSqlChangeLogParser.java
@@ -24,7 +24,7 @@ public boolean supports(String changeLogFile, ResourceAccessor resourceAccessor)
if (changeLogFile.endsWith(".sql")) {
reader = new BufferedReader(new InputStreamReader(openChangeLogFile(changeLogFile, resourceAccessor)));
- return reader.readLine().startsWith("--liquibase formatted");
+ return reader.readLine().matches("\\-\\-\\s*liquibase formatted.*");
} else {
return false;
}
@@ -60,8 +60,8 @@ public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParame
ChangeSet changeSet = null;
RawSQLChange change = null;
- Pattern changeSetPattern = Pattern.compile("\\-\\-changeset (\\w+):(\\w+).*", Pattern.CASE_INSENSITIVE);
- Pattern rollbackPattern = Pattern.compile("\\s*\\-\\-rollback (.*)", Pattern.CASE_INSENSITIVE);
+ Pattern changeSetPattern = Pattern.compile("\\-\\-[\\s]*changeset (\\w+):(\\w+).*", Pattern.CASE_INSENSITIVE);
+ Pattern rollbackPattern = Pattern.compile("\\s*\\-\\-[\\s]*rollback (.*)", Pattern.CASE_INSENSITIVE);
Pattern stripCommentsPattern = Pattern.compile(".*stripComments:(\\w+).*", Pattern.CASE_INSENSITIVE);
Pattern splitStatementsPattern = Pattern.compile(".*splitStatements:(\\w+).*", Pattern.CASE_INSENSITIVE);
Pattern endDelimiterPattern = Pattern.compile(".*endDelimiter:(\\w+).*", Pattern.CASE_INSENSITIVE);
@@ -87,14 +87,14 @@ public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParame
change.setSql(finalCurrentSql);
if (StringUtils.trimToNull(currentRollbackSql.toString()) != null) {
- try {
- if (currentRollbackSql.toString().trim().toLowerCase().matches("^not required.*")) {
- changeSet.addRollbackChange(new EmptyChange());
- } else {
- RawSQLChange rollbackChange = new RawSQLChange();
- rollbackChange.setSql(changeLogParameters.expandExpressions(currentRollbackSql.toString()));
- changeSet.addRollbackChange(rollbackChange);
- }
+ try {
+ if (currentRollbackSql.toString().trim().toLowerCase().matches("^not required.*")) {
+ changeSet.addRollbackChange(new EmptyChange());
+ } else {
+ RawSQLChange rollbackChange = new RawSQLChange();
+ rollbackChange.setSql(changeLogParameters.expandExpressions(currentRollbackSql.toString()));
+ changeSet.addRollbackChange(rollbackChange);
+ }
} catch (UnsupportedChangeException e) {
throw new RuntimeException(e);
}
View
31 ...ore/src/test/java/liquibase/parser/core/formattedsql/FormattedSqlChangeLogParserTest.java
@@ -47,7 +47,12 @@
"create table ${tablename} (\n" +
" id int primary key\n" +
");\n" +
- "--rollback drop table ${tablename};\n"
+ "--rollback drop table ${tablename};\n" +
+ "-- changeset mysql:1\n" +
+ "create table mysql_boo (\n" +
+ " id int primary key\n" +
+ ");\n" +
+ "-- rollback drop table mysql_boo;\n"
;
private static final String INVALID_CHANGELOG = "select * from table1";
@@ -61,12 +66,12 @@ public void supports() throws Exception {
@Test
public void parse() throws Exception {
ChangeLogParameters params = new ChangeLogParameters();
- params.set("tablename", "table4");
- DatabaseChangeLog changeLog = new MockFormattedSqlChangeLogParser(VALID_CHANGELOG).parse("asdf.sql", params, new JUnitResourceAccessor());
+ params.set("tablename", "table4");
+ DatabaseChangeLog changeLog = new MockFormattedSqlChangeLogParser(VALID_CHANGELOG).parse("asdf.sql", params, new JUnitResourceAccessor());
assertEquals("asdf.sql", changeLog.getLogicalFilePath());
- assertEquals(6, changeLog.getChangeSets().size());
+ assertEquals(7, changeLog.getChangeSets().size());
assertEquals("nvoxland", changeLog.getChangeSets().get(0).getAuthor());
assertEquals("1", changeLog.getChangeSets().get(0).getId());
@@ -128,11 +133,11 @@ public void parse() throws Exception {
assertEquals("nvoxland", changeLog.getChangeSets().get(4).getAuthor());
assertEquals("5", changeLog.getChangeSets().get(4).getId());
assertEquals(1, changeLog.getChangeSets().get(4).getRollBackChanges().length);
- assertTrue(changeLog.getChangeSets().get(4).getRollBackChanges()[0] instanceof EmptyChange);
+ assertTrue(changeLog.getChangeSets().get(4).getRollBackChanges()[0] instanceof EmptyChange);
- assertEquals("paikens", changeLog.getChangeSets().get(5).getAuthor());
+ assertEquals("paikens", changeLog.getChangeSets().get(5).getAuthor());
assertEquals("6", changeLog.getChangeSets().get(5).getId());
- assertEquals(1, changeLog.getChangeSets().get(5).getChanges().size());
+ assertEquals(1, changeLog.getChangeSets().get(5).getChanges().size());
assertTrue(changeLog.getChangeSets().get(5).getChanges().get(0) instanceof RawSQLChange);
assertEquals("create table table4 (\n" +
" id int primary key\n" +
@@ -140,6 +145,18 @@ public void parse() throws Exception {
assertEquals(1, changeLog.getChangeSets().get(5).getRollBackChanges().length);
assertTrue(changeLog.getChangeSets().get(5).getRollBackChanges()[0] instanceof RawSQLChange);
assertEquals("drop table table4;", ((RawSQLChange) changeLog.getChangeSets().get(5).getRollBackChanges()[0]).getSql());
+
+
+ assertEquals("mysql", changeLog.getChangeSets().get(6).getAuthor());
+ assertEquals("1", changeLog.getChangeSets().get(6).getId());
+ assertEquals(1, changeLog.getChangeSets().get(6).getChanges().size());
+ assertTrue(changeLog.getChangeSets().get(6).getChanges().get(0) instanceof RawSQLChange);
+ assertEquals("create table mysql_boo (\n" +
+ " id int primary key\n" +
+ ");", ((RawSQLChange) changeLog.getChangeSets().get(6).getChanges().get(0)).getSql());
+ assertEquals(1, changeLog.getChangeSets().get(6).getRollBackChanges().length);
+ assertTrue(changeLog.getChangeSets().get(6).getRollBackChanges()[0] instanceof RawSQLChange);
+ assertEquals("drop table mysql_boo;", ((RawSQLChange) changeLog.getChangeSets().get(6).getRollBackChanges()[0]).getSql());
}
private static class MockFormattedSqlChangeLogParser extends FormattedSqlChangeLogParser {
Please sign in to comment.
Something went wrong with that request. Please try again.