strip comments from sql before splitting ; (to avoid ; in comments)
This commit is contained in:
parent
f5c4c8e3e3
commit
7c1544d8f3
|
@ -30,7 +30,6 @@ import org.apache.commons.cli.ParseException;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -68,13 +67,6 @@ public abstract class BaseFlywayMigrateDatabaseCommand<T extends Enum> extends B
|
||||||
return MIGRATE_DATABASE;
|
return MIGRATE_DATABASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> provideUsageNotes() {
|
|
||||||
String versions = "The following versions are supported: " +
|
|
||||||
provideAllowedVersions().stream().map(Enum::name).collect(Collectors.joining(", "));
|
|
||||||
return Collections.singletonList(versions);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Options getOptions() {
|
public Options getOptions() {
|
||||||
Options retVal = new Options();
|
Options retVal = new Options();
|
||||||
|
|
|
@ -38,6 +38,7 @@ import java.util.regex.Pattern;
|
||||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||||
|
|
||||||
public class SchemaInitializationProvider implements ISchemaInitializationProvider {
|
public class SchemaInitializationProvider implements ISchemaInitializationProvider {
|
||||||
|
private static final Pattern ourSqlCommentPattern = Pattern.compile("(?m)^\\s*--.*$");
|
||||||
private final String mySchemaFileClassPath;
|
private final String mySchemaFileClassPath;
|
||||||
private final String mySchemaExistsIndicatorTable;
|
private final String mySchemaExistsIndicatorTable;
|
||||||
|
|
||||||
|
@ -76,6 +77,10 @@ public class SchemaInitializationProvider implements ISchemaInitializationProvid
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String stripComments(String theSqlString) {
|
||||||
|
return ourSqlCommentPattern.matcher(theSqlString).replaceAll("");
|
||||||
|
}
|
||||||
|
|
||||||
private static final Pattern ourTrailingCommaPattern = Pattern.compile(",(\\s+)\\)");
|
private static final Pattern ourTrailingCommaPattern = Pattern.compile(",(\\s+)\\)");
|
||||||
|
|
||||||
static String clean(String theStatement) {
|
static String clean(String theStatement) {
|
||||||
|
|
|
@ -11,4 +11,15 @@ public class SchemaInitializationProviderTest {
|
||||||
assertEquals("foo\n )", SchemaInitializationProvider.clean("foo,\n )"));
|
assertEquals("foo\n )", SchemaInitializationProvider.clean("foo,\n )"));
|
||||||
assertEquals("foo,bar\n )", SchemaInitializationProvider.clean("foo,bar\n )"));
|
assertEquals("foo,bar\n )", SchemaInitializationProvider.clean("foo,bar\n )"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStripComments() {
|
||||||
|
String input = "no comment\n" +
|
||||||
|
" --spacecomment \n" +
|
||||||
|
"so like definitely no comment\n" +
|
||||||
|
"-- nospace comment\n";
|
||||||
|
String expectedOutput = "no comment\n\n" +
|
||||||
|
"so like definitely no comment\n\n";
|
||||||
|
assertEquals(expectedOutput, SchemaInitializationProvider.stripComments(input));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue