mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-14 14:46:25 +00:00
#2284 - ENH: ddl-generator - add optional generation of idx_<platform>.migrations file
This commit is contained in:
1 parent
4ba26ee7b7
commit
589ee7a5ea
17 files changed
+293
-9
No files matched your search
+10
-8
@@ -27,20 +27,22 @@ public class DbMigrationGenerateTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DbMigrationGenerateTest.class);
|
||||
|
||||
@Test
|
||||
public void invokeTest() throws IOException {
|
||||
main(null);
|
||||
public static void main(String[] args) throws IOException {
|
||||
run("ebean-ddl-generator/src/test/resources");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
@Test
|
||||
public void invokeTest() throws IOException {
|
||||
run("src/test/resources");
|
||||
}
|
||||
|
||||
logger.info("start");
|
||||
public static void run(String pathToResources) throws IOException {
|
||||
logger.info("start current directory: " + new File(".").getAbsolutePath());
|
||||
|
||||
DefaultDbMigration migration = new DefaultDbMigration();
|
||||
|
||||
migration.setIncludeIndex(true);
|
||||
// We use src/test/resources as output directory (so we see in GIT if files will change)
|
||||
|
||||
migration.setPathToResources("src/test/resources");
|
||||
migration.setPathToResources(pathToResources);
|
||||
migration.setMigrationPath("db/migration");
|
||||
migration.setMigrationPath(null); // use the default for this test
|
||||
|
||||
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package io.ebeaninternal.dbmigration;
|
||||
|
||||
import io.ebean.config.dbplatform.DatabasePlatform;
|
||||
import io.ebean.config.dbplatform.h2.H2Platform;
|
||||
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class IndexMigrationTest {
|
||||
|
||||
@Test
|
||||
public void index() throws IOException {
|
||||
File topDir = new File("src/test/resources/dbmigration/index");
|
||||
if (!topDir.exists()) {
|
||||
throw new IllegalStateException("Not expected - dir does not exist " + topDir.getAbsolutePath());
|
||||
}
|
||||
DatabasePlatform pg = new PostgresPlatform();
|
||||
IndexMigration indexMigration = new IndexMigration(topDir, pg);
|
||||
indexMigration.generate(true);
|
||||
|
||||
|
||||
File expected = new File(topDir, "idx_postgres.migrations");
|
||||
assertThat(expected).exists();
|
||||
|
||||
final List<String> expectedLines = Arrays.asList(
|
||||
"-965417868, I__init_1.sql",
|
||||
"907060870, 1.0__hello.sql",
|
||||
"-1938594527, 1.1__foo.sql",
|
||||
"-1960070312, R__view_1.sql");
|
||||
|
||||
final List<String> lines = Files.readAllLines(expected.toPath(), StandardCharsets.UTF_8);
|
||||
assertThat(lines).containsAll(expectedLines);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void index2_withSubDirectories() throws IOException {
|
||||
File topDir = new File("src/test/resources/dbmigration/index2");
|
||||
if (!topDir.exists()) {
|
||||
throw new IllegalStateException("Not expected - dir does not exist " + topDir.getAbsolutePath());
|
||||
}
|
||||
DatabasePlatform pg = new H2Platform();
|
||||
IndexMigration indexMigration = new IndexMigration(topDir, pg);
|
||||
indexMigration.generate(true);
|
||||
|
||||
File expected = new File(topDir, "idx_h2.migrations");
|
||||
assertThat(expected).exists();
|
||||
|
||||
final List<String> expectedLines = Arrays.asList(
|
||||
"-965417868, I__init_1.sql",
|
||||
"-390611389, g1/1.0__a.sql",
|
||||
"1908338681, g1/1.1__b.sql",
|
||||
"-1776543936, g2/2.0__a.sql",
|
||||
"253052666, g2/2.1__2b.sql",
|
||||
"-1960070312, R__view_1.sql");
|
||||
|
||||
final List<String> lines = Files.readAllLines(expected.toPath(), StandardCharsets.UTF_8);
|
||||
assertThat(lines).containsAll(expectedLines);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package io.ebeaninternal.dbmigration;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class MChecksumTest {
|
||||
|
||||
@Test
|
||||
public void calculate() {
|
||||
File file = new File("src/test/resources/dbmigration/index/1.0__hello.sql");
|
||||
assertThat(file).exists();
|
||||
|
||||
assertThat(MChecksum.calculate(file)).isEqualTo(907060870);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user