added command line to create migrations
This commit is contained in:
46
src/main/java/jef/DatabaseOptions.java
Normal file
46
src/main/java/jef/DatabaseOptions.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package jef;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Getter
|
||||
public class DatabaseOptions {
|
||||
protected final String url;
|
||||
protected final String user;
|
||||
protected final String password;
|
||||
|
||||
protected final String migrationsPackage;
|
||||
|
||||
protected final String host;
|
||||
protected final String database;
|
||||
|
||||
public DatabaseOptions(String url, String user, String password, String migrationsPackage) {
|
||||
this.url = url;
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
|
||||
host = extractHost(url);
|
||||
database = extractDatabase(url);
|
||||
this.migrationsPackage = migrationsPackage;
|
||||
}
|
||||
|
||||
private static String extractHost(String url) {
|
||||
var pattern = Pattern.compile("^.*?//(.*?)/.*$");
|
||||
var matcher = pattern.matcher(url);
|
||||
if (!matcher.matches()) {
|
||||
throw new RuntimeException(new MalformedURLException("Could not extract host for url: " + url));
|
||||
}
|
||||
return matcher.group(1);
|
||||
}
|
||||
|
||||
private static String extractDatabase(String url) {
|
||||
var pattern = Pattern.compile("^.*?//.*?/(.*?)([?/].*)?$");
|
||||
var matcher = pattern.matcher(url);
|
||||
if (!matcher.matches()) {
|
||||
throw new RuntimeException(new MalformedURLException("Could not extract database for url: " + url));
|
||||
}
|
||||
return matcher.group(1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user