This commit is contained in:
wea_ondara
2022-11-27 08:27:55 +01:00
parent 7407d673fb
commit e1203eb5f4
4 changed files with 8 additions and 27 deletions

View File

@@ -39,6 +39,7 @@ public class MysqlMigrationTest {
private static final String GENERATE_MIGRATIONS_FOLDER = "target/test-generated-migrations/";
private static final String GENERATE_MIGRATIONS_FOLDER_SRC = GENERATE_MIGRATIONS_FOLDER + "src/";
private static final String GENERATE_MIGRATIONS_FOLDER_TARGET = GENERATE_MIGRATIONS_FOLDER + "target/";
private static final String PACKAGE_NAME = MysqlMigrationTest.class.getSimpleName();
@Test
public void test() throws Exception {
@@ -46,7 +47,7 @@ public class MysqlMigrationTest {
generateInitialMigration();
compileInitialMigration();
Class.forName("com.mysql.cj.jdbc.Driver").getDeclaredConstructor().newInstance();
var dboptions = new DatabaseOptions("jdbc:mysql://localhost/test", "test", "password", getClass().getSimpleName(), null);
var dboptions = new DatabaseOptions("jdbc:mysql://localhost/test", "test", "password", PACKAGE_NAME, null);
var ctxoptions = new DbContextOptions(dboptions);
var conn = DriverManager.getConnection(dboptions.getUrl(), dboptions.getUser(), dboptions.getPassword());
var sqlPlatform = new MysqlPlatform();
@@ -58,8 +59,8 @@ public class MysqlMigrationTest {
}
private void clearMigrationFolders() {
delRecursive(new File(GENERATE_MIGRATIONS_FOLDER_SRC + "MysqlMigrationTest"));
delRecursive(new File(GENERATE_MIGRATIONS_FOLDER_TARGET + "MysqlMigrationTest"));
delRecursive(new File(GENERATE_MIGRATIONS_FOLDER_SRC + PACKAGE_NAME));
delRecursive(new File(GENERATE_MIGRATIONS_FOLDER_TARGET + PACKAGE_NAME));
}
private void delRecursive(File f) {
@@ -76,9 +77,9 @@ public class MysqlMigrationTest {
var sqlPlatform = new MysqlPlatform();
var from = new ModelBuilder();
var to = ModelBuilder.from(Ctx.class);
var result = new MigrationCreator(sqlPlatform, from, to, "Initial", "MysqlMigrationTest", null).createMigration();
var result = new MigrationCreator(sqlPlatform, from, to, "Initial", PACKAGE_NAME, null).createMigration();
var dir = Path.of(GENERATE_MIGRATIONS_FOLDER_SRC, "MysqlMigrationTest").toFile();
var dir = Path.of(GENERATE_MIGRATIONS_FOLDER_SRC, PACKAGE_NAME).toFile();
dir.mkdirs();
var fileOptions = new OpenOption[]{StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE};
@@ -104,7 +105,7 @@ public class MysqlMigrationTest {
"-g", //debug symbols
"-d", GENERATE_MIGRATIONS_FOLDER_TARGET //target
));
Arrays.stream(new File(GENERATE_MIGRATIONS_FOLDER_SRC + "MysqlMigrationTest").listFiles(File::isFile)).map(File::getPath).forEach(params::add);
Arrays.stream(new File(GENERATE_MIGRATIONS_FOLDER_SRC + PACKAGE_NAME).listFiles(File::isFile)).map(File::getPath).forEach(params::add);
var process = new ProcessBuilder()
.command(params.toArray(String[]::new))
.inheritIO()