Add testcase, that uses all kinds of reserved keywords

This commit is contained in:
Roland Praml
2022-03-21 13:48:48 +01:00
parent 4077d906d1
commit 04d2a20945
93 changed files with 1129 additions and 64 deletions
@@ -6,6 +6,7 @@ import io.ebean.annotation.Platform;
import io.ebean.config.DatabaseConfig;
import io.ebean.config.dbplatform.DbHistorySupport;
import io.ebean.datasource.pool.ConnectionPool;
import misc.migration.v1_0.ETable;
import misc.migration.v1_1.EHistory;
import misc.migration.v1_1.EHistory2;
import org.junit.jupiter.api.Test;
@@ -84,7 +85,10 @@ public class DbMigrationTest extends BaseTestCase {
"migtest_mtm_c_migtest_mtm_m",
"migtest_mtm_m_migtest_mtm_c",
"migtest_oto_child",
"migtest_oto_master");
"migtest_oto_master",
"table",
"\"table\"",
"`table`");
((ConnectionPool)server().dataSource()).offline();
((ConnectionPool)server().dataSource()).online();
@@ -113,7 +117,7 @@ public class DbMigrationTest extends BaseTestCase {
assertThat(server().execute(update)).isEqualTo(2);
}
testReservedKeywords();
createHistoryEntities();
if (isOracle()) {
// Oracle does not like to convert varchar to integer
@@ -258,6 +262,32 @@ public class DbMigrationTest extends BaseTestCase {
}
}
// do some history tests with V1.1 models
private void testReservedKeywords() {
DatabaseConfig config = new DatabaseConfig();
config.setName(server().name());
config.loadFromProperties(server().pluginApi().config().getProperties());
config.setDataSource(server().dataSource());
config.setReadOnlyDataSource(server().dataSource());
config.setDdlGenerate(false);
config.setDdlRun(false);
config.setRegister(false);
config.setPackages(Collections.singletonList("misc.migration.v1_0"));
Database tmpServer = DatabaseFactory.create(config);
try {
ETable table = new misc.migration.v1_0.ETable();
table.setFrom("foo");
table.setTo("bar");
table.setIndex("id");
tmpServer.save(table);
table = tmpServer.find(ETable.class).where().eq("index", "id").findOne();
assert table != null;
} finally {
tmpServer.shutdown(false, false);
}
}
private void createHistoryEntities() {
SqlUpdate update = server().sqlUpdate("insert into migtest_e_history (id, test_string) values (1, '42')");
assertThat(server().execute(update)).isEqualTo(1);
@@ -0,0 +1,90 @@
package misc.migration.v1_0;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import io.ebean.annotation.DbComment;
import io.ebean.annotation.History;
import io.ebean.annotation.Index;
@Table(name = "`table`")
@Entity
@History
public class ETable {
@Column(name = "`index`")
@DbComment("this is a comment")
@Id
private String index;
@Column(name = "`from`")
@Index
private String from;
@Column(name = "`to`")
@Index(unique = true)
private String to;
@Column(name = "`varchar`")
@Index(unique = true)
private String varchar;
@ManyToOne
@JoinColumn(name = "`foreign`")
ETable foreign;
@OneToMany(mappedBy = "foreign")
List<ETable> foreigns;
public String getIndex() {
return index;
}
public void setIndex(String index) {
this.index = index;
}
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getTo() {
return to;
}
public void setTo(String to) {
this.to = to;
}
public String getVarchar() {
return varchar;
}
public void setVarchar(String varchar) {
this.varchar = varchar;
}
public ETable getForeign() {
return foreign;
}
public void setForeign(ETable foreign) {
this.foreign = foreign;
}
public List<ETable> getForeigns() {
return foreigns;
}
}
@@ -0,0 +1,49 @@
package misc.migration.v1_1;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import io.ebean.annotation.DbComment;
import io.ebean.annotation.History;
import io.ebean.annotation.Index;
@Table(name = "`table`")
@Entity
@History // FIXME: remove later
public class ETable {
@Column(name = "`index`")
@DbComment("this is an other comment")
@Id
private String index;
@Column(name = "`from`")
@Index
private String from;
@Column(name = "`to`")
@Index(unique = true)
private String to;
@Column(name = "`varchar`")
@Index(unique = true)
private String varchar;
@Column(name = "`select`")
@Index(unique = true)
private String select;
@ManyToOne
@JoinColumn(name = "`foreign`")
ETable foreign;
@OneToMany(mappedBy = "foreign")
List<ETable> foreigns;
}
@@ -0,0 +1,55 @@
package misc.migration.v1_2;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import io.ebean.annotation.DbComment;
import io.ebean.annotation.History;
import io.ebean.annotation.Index;
@Table(name = "`table`")
@Entity
@History
public class ETable {
@Column(name = "`index`")
@DbComment("this is a comment")
@Id
private String index;
@Column(name = "`from`")
@Index
private String from;
@Column(name = "`to`")
@Index(unique = true)
private String to;
@Column(name = "`varchar`")
@Index(unique = true)
private String varchar;
// Note: This column should be removed, (as it is also not present in V1.0)
// There is a limitation in history generation, that you cannot enable history while you have pending drops
// History-table will be generyted in V1.3 - SQL without that column, while base table still contains that column
// When creating the "with_history" view, the DB complains, because the tables do not match.
// In V1.4 the column will be dropped in base table AND history table.
// This could be probably fixed, by generating history table also with dropped columns
@Column(name = "`select`")
@Index(unique = true)
private String select;
@ManyToOne
@JoinColumn(name = "`foreign`")
ETable foreign;
@OneToMany(mappedBy = "foreign")
List<ETable> foreigns;
}