-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
293 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 0 additions & 98 deletions
98
r2dbc-migrate-core/src/main/java/name/nkonev/r2dbc/migrate/core/FilenameParser.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
r2dbc-migrate-core/src/main/java/name/nkonev/r2dbc/migrate/core/MigrationMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package name.nkonev.r2dbc.migrate.core; | ||
|
||
public class MigrationMetadata { | ||
private final long version; | ||
private final String description; | ||
private final boolean splitByLine; | ||
private final boolean transactional; | ||
private final boolean premigration; | ||
private final boolean substitute; | ||
|
||
public MigrationMetadata(long version, String description, boolean splitByLine, boolean transactional, boolean premigration, boolean substitute) { | ||
this.version = version; | ||
this.description = description; | ||
this.splitByLine = splitByLine; | ||
this.transactional = transactional; | ||
this.premigration = premigration; | ||
this.substitute = substitute; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public long getVersion() { | ||
return version; | ||
} | ||
|
||
public boolean isSplitByLine() { | ||
return splitByLine; | ||
} | ||
|
||
public boolean isTransactional() { | ||
return transactional; | ||
} | ||
|
||
public boolean isPremigration() { | ||
return premigration; | ||
} | ||
|
||
public boolean isSubstitute() { | ||
return substitute; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "MigrationMetadata{" + | ||
"version=" + version + | ||
", description='" + description + '\'' + | ||
", splitByLine=" + splitByLine + | ||
", transactional=" + transactional + | ||
", premigration=" + premigration + | ||
", substitute=" + substitute + | ||
'}'; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...c-migrate-core/src/main/java/name/nkonev/r2dbc/migrate/core/MigrationMetadataFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package name.nkonev.r2dbc.migrate.core; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public abstract class MigrationMetadataFactory { | ||
|
||
public static MigrationMetadata getMigrationMetadata(String filename) { | ||
final String sql = ".sql"; | ||
if (filename == null || !filename.endsWith(sql)) { | ||
throw new RuntimeException("File name should ends with " + sql); | ||
} | ||
String substring = filename.substring(0, filename.length() - sql.length()); | ||
String[] array = substring.split("__"); | ||
if (array.length == 3) { | ||
String modifiersRaw = array[2]; | ||
List<String> modifiers = Arrays.asList(modifiersRaw.split(",")); | ||
boolean nonTransactional = modifiers.contains("nontransactional"); | ||
boolean premigration = modifiers.contains("premigration"); | ||
boolean split = modifiers.contains("split"); | ||
boolean substitute = modifiers.contains("substitute"); | ||
return new MigrationMetadata(getVersion(array[0]), getDescription(array[1]), split, !nonTransactional, premigration, substitute); | ||
} else if (array.length == 2) { | ||
// no split | ||
return new MigrationMetadata(getVersion(array[0]), getDescription(array[1]), false, true, false, false); | ||
} else { | ||
throw new RuntimeException("Invalid file name '" + filename + "'"); | ||
} | ||
} | ||
|
||
public static MigrationMetadata getMigrationMetadata(long version, String description, Boolean splitByLine, Boolean transactional, Boolean premigration, Boolean substitute) { | ||
return new MigrationMetadata( | ||
version, | ||
description, | ||
Optional.ofNullable(splitByLine).orElse(false), | ||
Optional.ofNullable(transactional).orElse(false), | ||
Optional.ofNullable(premigration).orElse(false), | ||
Optional.ofNullable(substitute).orElse(false) | ||
); | ||
} | ||
|
||
private static long getVersion(String vPart) { | ||
String v = vPart.replace("V", ""); | ||
return Long.parseLong(v); | ||
} | ||
|
||
private static String getDescription(String descriptionPart) { | ||
return descriptionPart.replace("_", " "); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.