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

@@ -3,8 +3,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>jef</artifactId>
<groupId>jef</groupId>
<artifactId>jef</artifactId>
<version>0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -73,25 +73,6 @@ public class DbField<T> {
return entity.getKeys().stream().anyMatch(u -> u.getFields().size() == 1 && u.getFields().get(0) == this);
}
public DbField<T> setModelField(boolean modelField) {
isModelField = modelField;
return this;
}
public DbField<T> setDatabaseField(boolean databaseField) {
isDatabaseField = databaseField;
return this;
}
public DbField<T> setNotNull(boolean notNull) {
this.notNull = notNull;
return this;
}
public void setSqlType(String sqlType) {
this.sqlType = sqlType;
}
public void setGenerated(Generated.Type generated) {
Check.notNull(generated, "generated");
this.generated = generated;

View File

@@ -122,7 +122,6 @@ public class MigrationBuilderGenerator {
private String addForeignKeyOp(AddForeignKeyOperation op) {
imports.add(List.class);
imports.add(ForeignKeyConstraint.class);
imports.add(ForeignKeyConstraint.Action.class);
return "mb.addForeignKey(\"" + op.getName() + "\",\n"
+ " \"" + op.getTable() + "\",\n"
+ " List.of(" + op.getFields().stream().map(e -> "\"" + e + "\"").collect(Collectors.joining(", ")) + "),\n"

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()