mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1897 - Indexes names, like index, unique, primary and foreign keys does not honor ebean.allQuotedIdentifiers (#1898)
This commit is contained in:
+60
-3
@@ -3,14 +3,25 @@ package io.ebeaninternal.dbmigration.model.build;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.DatabaseFactory;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.DbConstraintNaming;
|
||||
import io.ebean.config.dbplatform.h2.H2Platform;
|
||||
import io.ebean.config.dbplatform.sqlserver.SqlServer17Platform;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.platform.DefaultConstraintMaxLength;
|
||||
import io.ebeaninternal.dbmigration.model.MColumn;
|
||||
import io.ebeaninternal.dbmigration.model.MCompoundForeignKey;
|
||||
import io.ebeaninternal.dbmigration.model.MTable;
|
||||
import io.ebeaninternal.dbmigration.model.ModelContainer;
|
||||
import io.ebeaninternal.dbmigration.model.visitor.VisitAllUsing;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.CKeyAssoc;
|
||||
import org.tests.model.basic.CKeyDetail;
|
||||
import org.tests.model.basic.CKeyParent;
|
||||
import org.tests.model.basic.CKeyParentId;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -24,9 +35,8 @@ public class ModelBuildBeanVisitorTest extends BaseTestCase {
|
||||
ModelContainer model = new ModelContainer();
|
||||
|
||||
DbConstraintNaming constraintNaming = defaultServer.getServerConfig().getConstraintNaming();
|
||||
|
||||
DefaultConstraintMaxLength maxLength = new DefaultConstraintMaxLength(60);
|
||||
ModelBuildContext ctx = new ModelBuildContext(model, constraintNaming, maxLength, true);
|
||||
constraintNaming.setMaxLength(new DefaultConstraintMaxLength(60));
|
||||
ModelBuildContext ctx = new ModelBuildContext(model, new H2Platform(), constraintNaming, true);
|
||||
|
||||
ModelBuildBeanVisitor addTable = new ModelBuildBeanVisitor(ctx);
|
||||
|
||||
@@ -39,6 +49,53 @@ public class ModelBuildBeanVisitorTest extends BaseTestCase {
|
||||
assert_discriminatorColumn_length(model);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_allQuoted() {
|
||||
|
||||
ModelContainer model = new ModelContainer();
|
||||
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
config.setName("h2");
|
||||
config.loadFromProperties();
|
||||
config.setName("h2other");
|
||||
config.setAllQuotedIdentifiers(true);
|
||||
config.setDdlGenerate(false);
|
||||
config.setDdlRun(false);
|
||||
config.setDdlExtra(false);
|
||||
config.setDefaultServer(false);
|
||||
config.setRegister(false);
|
||||
|
||||
config.addClass(CKeyDetail.class);
|
||||
config.addClass(CKeyParent.class);
|
||||
config.addClass(CKeyAssoc.class);
|
||||
config.addClass(CKeyParentId.class);
|
||||
config.setDbOffline(true);
|
||||
config.setDatabasePlatform(new SqlServer17Platform());
|
||||
|
||||
final SpiEbeanServer database = (SpiEbeanServer)DatabaseFactory.create(config);
|
||||
|
||||
|
||||
ModelBuildContext ctx = new ModelBuildContext(model, config.getDatabasePlatform(), config.getConstraintNaming(), true);
|
||||
|
||||
ModelBuildBeanVisitor addTable = new ModelBuildBeanVisitor(ctx);
|
||||
|
||||
new VisitAllUsing(addTable, database).visitAllBeans();
|
||||
|
||||
MTable parent = model.getTable("[CKeyParent]");
|
||||
assertThat(parent.getPkName()).isEqualTo("[pk_CKeyParent]");
|
||||
|
||||
MTable detail = model.getTable("[CKeyDetail]");
|
||||
assertThat(detail.getPkName()).isEqualTo("[pk_CKeyDetail]");
|
||||
|
||||
final List<MCompoundForeignKey> compoundKeys = detail.getCompoundKeys();
|
||||
assertThat(compoundKeys).hasSize(1);
|
||||
final MCompoundForeignKey fkey = compoundKeys.get(0);
|
||||
assertThat(fkey.getName()).isEqualTo("[fk_CKeyDetail_parent]");
|
||||
assertThat(fkey.getIndexName()).isEqualTo("[ix_CKeyDetail_parent]");
|
||||
|
||||
database.shutdown(true, false);
|
||||
}
|
||||
|
||||
private void assert_compound_pk(ModelContainer model) {
|
||||
MTable item = model.getTable("item");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user