added command line to create migrations

This commit is contained in:
wea_ondara
2022-11-23 13:50:54 +01:00
parent 17d71eb2f3
commit 915fc4a87b
43 changed files with 1183 additions and 61 deletions

View 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);
}
}