mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
WIP Db Migration compound keys
This commit is contained in:
+1
-6
@@ -2,9 +2,6 @@ package com.avaje.ebean.dbmigration.ddlgeneration.platform;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class DdlNamingConventionTest {
|
||||
@@ -14,9 +11,7 @@ public class DdlNamingConventionTest {
|
||||
@Test
|
||||
public void testPrimaryKeyName() throws Exception {
|
||||
|
||||
List<String> cols = new ArrayList<String>();
|
||||
cols.add("[jim]");
|
||||
cols.add("`jack`");
|
||||
String[] cols = {"[jim]","`jack`"};
|
||||
assertThat(defaultNaming.primaryKeyName("[cat].[sce].[foo_bar]", cols)).isEqualTo("pk_foo_bar");
|
||||
}
|
||||
|
||||
|
||||
+39
-4
@@ -2,8 +2,13 @@ package com.avaje.ebean.dbmigration.model.build;
|
||||
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.EbeanServerFactory;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebean.dbmigration.ddlgeneration.DdlWrite;
|
||||
import com.avaje.ebean.dbmigration.ddlgeneration.Helper;
|
||||
import com.avaje.ebean.dbmigration.migration.Migration;
|
||||
import com.avaje.ebean.dbmigration.migrationreader.MigrationXmlReader;
|
||||
import com.avaje.ebean.dbmigration.model.CurrentModel;
|
||||
import com.avaje.ebean.dbmigration.model.MTable;
|
||||
import com.avaje.ebean.dbmigration.model.ModelContainer;
|
||||
@@ -14,13 +19,13 @@ import com.avaje.tests.model.basic.CKeyParent;
|
||||
import com.avaje.tests.model.basic.CKeyParentId;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ModelBuild_compoundKeyTest extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
private SpiEbeanServer getServer() {
|
||||
ServerConfig config = new ServerConfig();
|
||||
config.setName("h2");
|
||||
config.loadFromProperties();
|
||||
@@ -36,7 +41,13 @@ public class ModelBuild_compoundKeyTest extends BaseTestCase {
|
||||
config.addClass(CKeyParentId.class);
|
||||
|
||||
|
||||
SpiEbeanServer ebeanServer = (SpiEbeanServer)EbeanServerFactory.create(config);
|
||||
return (SpiEbeanServer) EbeanServerFactory.create(config);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws IOException {
|
||||
|
||||
SpiEbeanServer ebeanServer = getServer();
|
||||
|
||||
CurrentModel currentModel = new CurrentModel(ebeanServer);
|
||||
ModelContainer model = currentModel.read();
|
||||
@@ -46,6 +57,30 @@ public class ModelBuild_compoundKeyTest extends BaseTestCase {
|
||||
|
||||
assertThat(parent).isNotNull();
|
||||
assertThat(detail).isNotNull();
|
||||
assertThat(parent.primaryKeyColumns()).hasSize(2);
|
||||
assertThat(detail.getCompoundKeys()).hasSize(1);
|
||||
|
||||
String apply = Helper.asText(this, "/assert/ModelBuild_compoundKeyTest/apply.sql");
|
||||
|
||||
String createDdl = currentModel.getCreateDdl();
|
||||
assertThat(createDdl).isEqualTo(apply);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFromMigration() throws IOException {
|
||||
|
||||
|
||||
Migration migration = MigrationXmlReader.read("/container/test-compoundkey.xml");
|
||||
|
||||
SpiEbeanServer ebeanServer = getServer();
|
||||
CurrentModel currentModel = new CurrentModel(ebeanServer);
|
||||
currentModel.setChangeSet(migration.getChangeSet().get(0));
|
||||
|
||||
String createDdl = currentModel.getCreateDdl();
|
||||
String apply = Helper.asText(this, "/assert/ModelBuild_compoundKeyTest/apply.sql");
|
||||
|
||||
assertThat(createDdl).isEqualTo(apply);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user