cleanup
This commit is contained in:
@@ -3,8 +3,8 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>jef</artifactId>
|
|
||||||
<groupId>jef</groupId>
|
<groupId>jef</groupId>
|
||||||
|
<artifactId>jef</artifactId>
|
||||||
<version>0.1</version>
|
<version>0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -73,25 +73,6 @@ public class DbField<T> {
|
|||||||
return entity.getKeys().stream().anyMatch(u -> u.getFields().size() == 1 && u.getFields().get(0) == this);
|
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) {
|
public void setGenerated(Generated.Type generated) {
|
||||||
Check.notNull(generated, "generated");
|
Check.notNull(generated, "generated");
|
||||||
this.generated = generated;
|
this.generated = generated;
|
||||||
|
|||||||
@@ -122,7 +122,6 @@ public class MigrationBuilderGenerator {
|
|||||||
private String addForeignKeyOp(AddForeignKeyOperation op) {
|
private String addForeignKeyOp(AddForeignKeyOperation op) {
|
||||||
imports.add(List.class);
|
imports.add(List.class);
|
||||||
imports.add(ForeignKeyConstraint.class);
|
imports.add(ForeignKeyConstraint.class);
|
||||||
imports.add(ForeignKeyConstraint.Action.class);
|
|
||||||
return "mb.addForeignKey(\"" + op.getName() + "\",\n"
|
return "mb.addForeignKey(\"" + op.getName() + "\",\n"
|
||||||
+ " \"" + op.getTable() + "\",\n"
|
+ " \"" + op.getTable() + "\",\n"
|
||||||
+ " List.of(" + op.getFields().stream().map(e -> "\"" + e + "\"").collect(Collectors.joining(", ")) + "),\n"
|
+ " List.of(" + op.getFields().stream().map(e -> "\"" + e + "\"").collect(Collectors.joining(", ")) + "),\n"
|
||||||
|
|||||||
@@ -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 = "target/test-generated-migrations/";
|
||||||
private static final String GENERATE_MIGRATIONS_FOLDER_SRC = GENERATE_MIGRATIONS_FOLDER + "src/";
|
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 GENERATE_MIGRATIONS_FOLDER_TARGET = GENERATE_MIGRATIONS_FOLDER + "target/";
|
||||||
|
private static final String PACKAGE_NAME = MysqlMigrationTest.class.getSimpleName();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
@@ -46,7 +47,7 @@ public class MysqlMigrationTest {
|
|||||||
generateInitialMigration();
|
generateInitialMigration();
|
||||||
compileInitialMigration();
|
compileInitialMigration();
|
||||||
Class.forName("com.mysql.cj.jdbc.Driver").getDeclaredConstructor().newInstance();
|
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 ctxoptions = new DbContextOptions(dboptions);
|
||||||
var conn = DriverManager.getConnection(dboptions.getUrl(), dboptions.getUser(), dboptions.getPassword());
|
var conn = DriverManager.getConnection(dboptions.getUrl(), dboptions.getUser(), dboptions.getPassword());
|
||||||
var sqlPlatform = new MysqlPlatform();
|
var sqlPlatform = new MysqlPlatform();
|
||||||
@@ -58,8 +59,8 @@ public class MysqlMigrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void clearMigrationFolders() {
|
private void clearMigrationFolders() {
|
||||||
delRecursive(new File(GENERATE_MIGRATIONS_FOLDER_SRC + "MysqlMigrationTest"));
|
delRecursive(new File(GENERATE_MIGRATIONS_FOLDER_SRC + PACKAGE_NAME));
|
||||||
delRecursive(new File(GENERATE_MIGRATIONS_FOLDER_TARGET + "MysqlMigrationTest"));
|
delRecursive(new File(GENERATE_MIGRATIONS_FOLDER_TARGET + PACKAGE_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void delRecursive(File f) {
|
private void delRecursive(File f) {
|
||||||
@@ -76,9 +77,9 @@ public class MysqlMigrationTest {
|
|||||||
var sqlPlatform = new MysqlPlatform();
|
var sqlPlatform = new MysqlPlatform();
|
||||||
var from = new ModelBuilder();
|
var from = new ModelBuilder();
|
||||||
var to = ModelBuilder.from(Ctx.class);
|
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();
|
dir.mkdirs();
|
||||||
|
|
||||||
var fileOptions = new OpenOption[]{StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE};
|
var fileOptions = new OpenOption[]{StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE};
|
||||||
@@ -104,7 +105,7 @@ public class MysqlMigrationTest {
|
|||||||
"-g", //debug symbols
|
"-g", //debug symbols
|
||||||
"-d", GENERATE_MIGRATIONS_FOLDER_TARGET //target
|
"-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()
|
var process = new ProcessBuilder()
|
||||||
.command(params.toArray(String[]::new))
|
.command(params.toArray(String[]::new))
|
||||||
.inheritIO()
|
.inheritIO()
|
||||||
|
|||||||
Reference in New Issue
Block a user