mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1920 Support @Index concurrently and definition
This commit is contained in:
@@ -3,17 +3,12 @@ package io.ebeaninternal.dbmigration;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.SqlRow;
|
||||
import io.ebean.SqlUpdate;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.annotation.IgnorePlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.migration.ddl.DdlRunner;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.Helper;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -25,28 +20,8 @@ public class DbMigrationTest extends BaseTestCase {
|
||||
runScript(expectErrors, ddl, scriptName);
|
||||
}
|
||||
|
||||
private void runScript(boolean expectErrors, String content, String scriptName) {
|
||||
|
||||
DdlRunner runner = new DdlRunner(expectErrors, scriptName);
|
||||
|
||||
Transaction transaction = server().createTransaction();
|
||||
Connection connection = transaction.getConnection();
|
||||
try {
|
||||
if (expectErrors) {
|
||||
connection.setAutoCommit(true);
|
||||
}
|
||||
runner.runAll(content, connection);
|
||||
if (expectErrors) {
|
||||
connection.setAutoCommit(false);
|
||||
}
|
||||
transaction.commit();
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new PersistenceException("Failed to run script", e);
|
||||
|
||||
} finally {
|
||||
transaction.end();
|
||||
}
|
||||
private void runScript(boolean useAutoCommit, String content, String scriptName) {
|
||||
server().script().runScript(scriptName, content, useAutoCommit);
|
||||
}
|
||||
|
||||
@IgnorePlatform({Platform.ORACLE, Platform.NUODB})
|
||||
@@ -188,21 +163,29 @@ public class DbMigrationTest extends BaseTestCase {
|
||||
}
|
||||
|
||||
private void cleanup(String ... tables) {
|
||||
|
||||
final boolean sqlServer = isSqlServer();
|
||||
final boolean postgres = isPostgres();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String table : tables) {
|
||||
// simple and stupid try to execute all commands on all dialects.
|
||||
sb.append("alter table ").append(table).append(" set ( system_versioning = OFF );\n");
|
||||
sb.append("alter table ").append(table).append(" drop system versioning;\n");
|
||||
sb.append("drop table ").append(table).append(";\n");
|
||||
sb.append("drop table ").append(table).append(" cascade;\n");
|
||||
sb.append("drop table ").append(table).append("_history;\n");
|
||||
sb.append("drop table ").append(table).append("_history cascade;\n");
|
||||
if (sqlServer) {
|
||||
sb.append("alter table ").append(table).append(" set ( system_versioning = OFF );\n");
|
||||
sb.append("alter table ").append(table).append(" drop system versioning;\n");
|
||||
}
|
||||
if (postgres) {
|
||||
sb.append("drop table ").append(table).append(" cascade;\n");
|
||||
sb.append("drop table ").append(table).append("_history cascade;\n");
|
||||
} else {
|
||||
sb.append("drop table ").append(table).append(";\n");
|
||||
sb.append("drop table ").append(table).append("_history;\n");
|
||||
}
|
||||
sb.append("drop view ").append(table).append("_with_history;\n");
|
||||
sb.append("drop sequence ").append(table).append("_seq;\n");
|
||||
}
|
||||
|
||||
runScript(true, sb.toString(), "cleanup");
|
||||
runScript(true, sb.toString(), "cleanup");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class IndexDefinitionTest {
|
||||
|
||||
private static final String[] simpleCol1 = new String[]{"one"};
|
||||
private static final String[] simpleCol2 = new String[]{"one","two"};
|
||||
private static final String[] formulaCol1 = new String[]{"lower(one)"};
|
||||
private static final String[] formulaCol2 = new String[]{"one","lower(two)"};
|
||||
|
||||
@Test
|
||||
public void isUniqueConstraint_TRUE_when_simpleMultiColumn() {
|
||||
assertTrue(new IndexDefinition(simpleCol1).isUniqueConstraint());
|
||||
assertTrue(new IndexDefinition(simpleCol2).isUniqueConstraint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isUniqueConstraint_NOT_when_columnWithFormula() {
|
||||
assertFalse(new IndexDefinition(formulaCol1).isUniqueConstraint());
|
||||
assertFalse(new IndexDefinition(formulaCol2).isUniqueConstraint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isUniqueConstraint_NOT_when_concurrentTrue() {
|
||||
assertFalse(new IndexDefinition(simpleCol1, "name", true, null, true, null).isUniqueConstraint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isUniqueConstraint_NOT_when_definitionNotEmpty() {
|
||||
assertFalse(new IndexDefinition(simpleCol1, "name", true, null, false, "create index foo").isUniqueConstraint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isUniqueConstraint_TRUE_otherwise() {
|
||||
assertTrue(new IndexDefinition(simpleCol1, "name", true, null, false, "").isUniqueConstraint());
|
||||
assertTrue(new IndexDefinition(simpleCol1, "name", true, null, false, null).isUniqueConstraint());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user