fix migration generation where sqltype was not properly set; also fix tests for that
This commit is contained in:
17
core/pom.xml
17
core/pom.xml
@@ -16,4 +16,21 @@
|
|||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin><!-- generate tests jar so that test utils can be used in downstream projects -->
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.2.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>test-jar</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
@@ -23,5 +23,12 @@
|
|||||||
<artifactId>core</artifactId>
|
<artifactId>core</artifactId>
|
||||||
<version>${project.parent.version}</version>
|
<version>${project.parent.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>jef</groupId>
|
||||||
|
<artifactId>core</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<type>test-jar</type>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@@ -251,6 +251,7 @@ public class MigrationCreator {
|
|||||||
if (fromField == null) {
|
if (fromField == null) {
|
||||||
handledTo.add(toField);
|
handledTo.add(toField);
|
||||||
steps.add(new AddFieldOperation.Builder(toField.getEntity().getName(), toField.getName())
|
steps.add(new AddFieldOperation.Builder(toField.getEntity().getName(), toField.getName())
|
||||||
|
.sqlType(getSqlType(toField))
|
||||||
.notNull(toField.isNotNull()));
|
.notNull(toField.isNotNull()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
package jef.model.migration.creator;
|
package jef.model.migration.creator;
|
||||||
|
|
||||||
import jef.model.DbContext;
|
import jef.model.DbContext;
|
||||||
|
import jef.model.DbEntityBuilder;
|
||||||
|
import jef.model.DbFieldBuilder;
|
||||||
import jef.model.ModelBuilder;
|
import jef.model.ModelBuilder;
|
||||||
|
import jef.platform.base.SqlTypeMapper;
|
||||||
|
import jef.serializable.SerializableObject;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@@ -14,6 +18,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static jef.model.ModelBuilderCloneTest.debugHelper;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class MigrationCreatorTestBase {
|
public class MigrationCreatorTestBase {
|
||||||
@@ -47,6 +52,8 @@ public class MigrationCreatorTestBase {
|
|||||||
compile(packageName, className, snapshotJava);
|
compile(packageName, className, snapshotJava);
|
||||||
var clazz = (Class<? extends DbContext>) loadClass(packageName, className);
|
var clazz = (Class<? extends DbContext>) loadClass(packageName, className);
|
||||||
var mb = ModelBuilder.from(clazz);
|
var mb = ModelBuilder.from(clazz);
|
||||||
|
applySqlTypes(mb);
|
||||||
|
debugHelper(from, mb);
|
||||||
assertEquals(from, mb);
|
assertEquals(from, mb);
|
||||||
} catch (AssertionError | RuntimeException e) {
|
} catch (AssertionError | RuntimeException e) {
|
||||||
throw e;
|
throw e;
|
||||||
@@ -62,6 +69,8 @@ public class MigrationCreatorTestBase {
|
|||||||
compile(packageName, className, snapshotJava);
|
compile(packageName, className, snapshotJava);
|
||||||
var clazz = (Class<? extends DbContext>) loadClass(packageName, className);
|
var clazz = (Class<? extends DbContext>) loadClass(packageName, className);
|
||||||
var mb = ModelBuilder.from(clazz);
|
var mb = ModelBuilder.from(clazz);
|
||||||
|
applySqlTypes(mb);
|
||||||
|
debugHelper(to, mb);
|
||||||
assertEquals(to, mb);
|
assertEquals(to, mb);
|
||||||
} catch (AssertionError | RuntimeException e) {
|
} catch (AssertionError | RuntimeException e) {
|
||||||
throw e;
|
throw e;
|
||||||
@@ -70,6 +79,16 @@ public class MigrationCreatorTestBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void applySqlTypes(ModelBuilder mb) {
|
||||||
|
for (DbEntityBuilder<? extends SerializableObject> entity : mb.entities()) {
|
||||||
|
for (DbFieldBuilder<?> field : entity.fields()) {
|
||||||
|
if (field.getField().getSqlType() == null) {
|
||||||
|
field.getField().setSqlType(new SqlTypeMapper().map(field.getField().getTypeName()).orElseThrow());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private File compile(String packageName, String className, String java) {
|
private File compile(String packageName, String className, String java) {
|
||||||
try {//src
|
try {//src
|
||||||
File srcdir = new File(getSourcesFilesDir(), packageName.replace(".", File.separator));
|
File srcdir = new File(getSourcesFilesDir(), packageName.replace(".", File.separator));
|
||||||
|
|||||||
Reference in New Issue
Block a user