Regenerated scripts & tests

This commit is contained in:
Roland Praml committed 2022-02-07 14:07:10 +01:00
1 parent a93e2e05c5
commit cb89b903fd
101 files changed
+315 -5981

No files matched your search

@@ -11,6 +11,7 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
@@ -32,10 +33,18 @@ public class DbMigrationDropHistoryTest {
main(null);
}
@Test
public void lastVersion_no_v_Prefix() {
File d = new File("src/test/resources/migrationtest-history/dbmigration");
assertThat(LastMigration.lastVersion(d, null)).isEqualTo("1.2");
}
public static void main(String[] args) throws IOException {
logger.info("start");
// First, we clean up the output-directory
Files.walk(Paths.get("src/test/resources/migrationtest-history"))
.filter(Files::isRegularFile).map(Path::toFile).forEach(File::delete);
DefaultDbMigration migration = new DefaultDbMigration();
// We use src/test/resources as output directory (so we see in GIT if files will change)
@@ -12,6 +12,7 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import static org.assertj.core.api.Assertions.assertThat;
@@ -28,7 +29,7 @@ public class DbMigrationGenerateTest {
private static final Logger logger = LoggerFactory.getLogger(DbMigrationGenerateTest.class);
public static void main(String[] args) throws IOException {
run("ebean-ddl-generator/src/test/resources");
run("ebean-test/src/test/resources");
}
@Test
@@ -39,25 +40,40 @@ public class DbMigrationGenerateTest {
public static void run(String pathToResources) throws IOException {
logger.info("start current directory: " + new File(".").getAbsolutePath());
// First, we clean up the output-directory
Files.walk(Paths.get(pathToResources, "migrationtest"))
.filter(Files::isRegularFile).map(Path::toFile).forEach(File::delete);
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(pathToResources);
migration.setMigrationPath("db/migration");
migration.setMigrationPath(null); // use the default for this test
// migration.addPlatform(Platform.GENERIC, "generic"); there is no ddl handler for generic
// migration.addPlatform(Platform.SQLANYWHERE, "sqlanywhere"); and sqlanywhere
migration.addPlatform(Platform.DB2);
migration.addPlatform(Platform.CLICKHOUSE);
migration.addPlatform(Platform.COCKROACH);
migration.addPlatform(Platform.DB2FORI);
migration.addPlatform(Platform.DB2LUW);
migration.addPlatform(Platform.DB2ZOS);
migration.addPlatform(Platform.GENERIC);
migration.addPlatform(Platform.H2);
migration.addPlatform(Platform.HSQLDB, "hsqldb");
migration.addPlatform(Platform.MYSQL, "mysql");
migration.addPlatform(Platform.MYSQL55, "mysql55");
migration.addPlatform(Platform.POSTGRES);
migration.addPlatform(Platform.ORACLE);
migration.addPlatform(Platform.SQLITE);
migration.addPlatform(Platform.SQLSERVER17, "sqlserver17");
migration.addPlatform(Platform.HANA);
migration.addPlatform(Platform.HSQLDB);
migration.addPlatform(Platform.MARIADB);
migration.addPlatform(Platform.MARIADB, "mariadb-noprocs");
migration.addPlatform(Platform.MYSQL);
migration.addPlatform(Platform.MYSQL55);
migration.addPlatform(Platform.NUODB);
migration.addPlatform(Platform.ORACLE);
migration.addPlatform(Platform.ORACLE11);
migration.addPlatform(Platform.POSTGRES);
migration.addPlatform(Platform.POSTGRES9);
migration.addPlatform(Platform.SQLANYWHERE);
migration.addPlatform(Platform.SQLITE);
migration.addPlatform(Platform.SQLSERVER16);
migration.addPlatform(Platform.SQLSERVER17);
migration.addPlatform(Platform.YUGABYTE);
DatabaseConfig config = new DatabaseConfig();
config.setName("migrationtest");
@@ -66,16 +82,10 @@ public class DbMigrationGenerateTest {
config.setDefaultServer(false);
config.getProperties().put("ebean.hana.generateUniqueDdl", "true"); // need to generate unique statements to prevent them from being filtered out as duplicates by the DdlRunner
config.setPackages(Arrays.asList("misc.migration.v1_0"));
Database server = DatabaseFactory.create(config);
migration.setServer(server);
// First, we clean up the output-directory
assertThat(migration.migrationDirectory().getAbsolutePath()).contains("migrationtest");
Files.walk(migration.migrationDirectory().toPath())
.filter(Files::isRegularFile).map(Path::toFile).forEach(File::delete);
// then we generate migration scripts for v1_0
assertThat(migration.generateMigration()).isEqualTo("1.0__initial");
// and we check repeatative calls
@@ -1,30 +1,38 @@
package io.ebeaninternal.dbmigration;
import io.localtest.BaseTestCase;
import io.ebean.BaseTestCase;
import io.ebean.SqlRow;
import io.ebean.SqlUpdate;
import io.ebean.annotation.IgnorePlatform;
import io.ebean.annotation.Platform;
import io.ebeaninternal.dbmigration.ddlgeneration.Helper;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class DbMigrationTest extends BaseTestCase {
private void runScript(boolean expectErrors, String scriptName) throws IOException {
String ddl = Helper.asText(this, "/dbmigration/migrationtest/" + server().platform().name().toLowerCase() + "/" + scriptName);
runScript(expectErrors, ddl, scriptName);
private void runScript(String scriptName) throws IOException {
URL url = getClass().getResource("/migrationtest/dbmigration/" + server().platform().name().toLowerCase() + "/" + scriptName);
assert url != null : scriptName + " not found";
server().script().run(url);
}
@Test
public void lastVersion() {
File d = new File("src/test/resources/migrationtest/dbmigration/h2");
assertThat(LastMigration.lastVersion(d, null)).isEqualTo("1.4");
assertThat(LastMigration.nextVersion(d, null, false)).isEqualTo("1.5");
assertThat(LastMigration.nextVersion(d, null, true)).isEqualTo("1.4");
}
private void runScript(boolean useAutoCommit, String content, String scriptName) {
server().script().runScript(scriptName, content, useAutoCommit);
}
@IgnorePlatform({Platform.ORACLE, Platform.NUODB, Platform.MARIADB})
@IgnorePlatform({Platform.ORACLE, Platform.NUODB, Platform.POSTGRES, Platform.YUGABYTE})
// Note: Postgres locks up on build server
// Note: YUGABYTE complains on "alter table migtest_e_basic alter column status set not null;"
@Test
public void testRunMigration() throws IOException {
// first clean up previously created objects
@@ -50,16 +58,17 @@ public class DbMigrationTest extends BaseTestCase {
"migtest_fk_set_null",
"migtest_mtm_c",
"migtest_mtm_m",
"migtest_mtm_m_phone_numbers",
"migtest_mtm_c_migtest_mtm_m",
"migtest_mtm_m_migtest_mtm_c",
"migtest_oto_child",
"migtest_oto_master");
if (isSqlServer()) { // || isMySql()
runScript(false, "I__create_procs.sql");
if (isSqlServer() || isMariaDB()) { // || isMySql()
runScript("I__create_procs.sql");
}
runScript(false, "1.0__initial.sql");
runScript("1.0__initial.sql");
if (isOracle() || isHana()) {
SqlUpdate update = server().sqlUpdate("insert into migtest_e_basic (id, old_boolean, user_id) values (1, :false, 1)");
@@ -80,7 +89,7 @@ public class DbMigrationTest extends BaseTestCase {
createHistoryEntities();
// Run migration
runScript(false, "1.1.sql");
runScript("1.1.sql");
List<SqlRow> result = server().sqlQuery("select * from migtest_e_basic order by id").findList();
assertThat(result).hasSize(2);
@@ -104,24 +113,20 @@ public class DbMigrationTest extends BaseTestCase {
assertThat(row.getBoolean("new_boolean_field2")).isTrue();
//assertThat(row.getTimestamp("some_date")).isCloseTo(new Date(), 60_000); // allow 1 minute delta
runScript(false, "1.2__dropsFor_1.1.sql");
runScript("1.2__dropsFor_1.1.sql");
// Oracle caches the statement and does not detect schema change. It fails with
// an ORA-01007
if (isOracle()) {
result = server().sqlQuery("select * from migtest_e_basic order by id,id").findList();
} else {
result = server().sqlQuery("select * from migtest_e_basic order by id").findList();
}
result = server().sqlQuery("select * from migtest_e_basic order by id,status").findList();
assertThat(result).hasSize(2);
row = result.get(0);
assertThat(row.keySet()).doesNotContain("old_boolean", "old_boolean2");
runScript(false, "1.3.sql");
runScript(false, "1.4__dropsFor_1.3.sql");
runScript("1.3.sql");
runScript("1.4__dropsFor_1.3.sql");
// now DB structure shoud be the same as v1_0
result = server().sqlQuery("select * from migtest_e_basic order by id").findList();
// now DB structure shoud be the same as v1_0 - perform a diffent query.
result = server().sqlQuery("select * from migtest_e_basic order by id,name").findList();
assertThat(result).hasSize(2);
row = result.get(0);
assertThat(row.keySet()).contains("old_boolean", "old_boolean2");
@@ -184,8 +189,7 @@ public class DbMigrationTest extends BaseTestCase {
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");
server().script().runScript("cleanup", sb.toString(), true);
server().script().runScript("cleanup", sb.toString(), true);
}
}
@@ -1,85 +0,0 @@
package io.ebeaninternal.dbmigration;
import io.ebean.Database;
import io.ebean.DatabaseFactory;
import io.ebean.annotation.Platform;
import io.ebean.config.DatabaseConfig;
import io.ebean.config.PlatformConfig;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Class to test the alternative drop behaviour using stored procedures for MySql databases .
*
* @author Jonas P&ouml;hler, FOCONIS AG
*/
public class MysqlGenerateMigrationTest {
@AfterEach
public void resetPendingDropsProperty() {
System.clearProperty("ddl.migration.pendingDropsFor");
}
@Test
public void testMysqlStoredProcedures() throws Exception {
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.addPlatform(Platform.MYSQL, "mysql");
final PlatformConfig platformConfig = new PlatformConfig();
platformConfig.setUseMigrationStoredProcedures(true);
DatabaseConfig config = new DatabaseConfig();
config.setName("migrationtest");
config.loadFromProperties();
config.setPlatformConfig(platformConfig);
config.setRegister(false);
config.setDefaultServer(false);
config.getProperties().put("ebean.migration.migrationPath", "db/migration/mysql");
config.setPackages(Arrays.asList("misc.migration.mysql_v1_0"));
Database server = DatabaseFactory.create(config);
migration.setServer(server);
migration.setMigrationPath("mysql/procedures");
// First, we clean up the output-directory
assertThat(migration.migrationDirectory().getAbsolutePath()).contains("procedures");
Files.walk(migration.migrationDirectory().toPath())
.filter(Files::isRegularFile)
.map(Path::toFile).forEach(File::delete);
// then we generate migration scripts for v1_0
assertThat(migration.generateMigration()).isEqualTo("1.0__initial");
config.setPackages(Arrays.asList("misc.migration.mysql_v1_1"));
server.shutdown();
server = DatabaseFactory.create(config);
migration.setServer(server);
migration.setMigrationPath("mysql/procedures");
assertThat(migration.generateMigration()).isEqualTo("1.1");
System.setProperty("ddl.migration.pendingDropsFor", "1.1");
assertThat(migration.generateMigration()).isEqualTo("1.2__dropsFor_1.1");
final Path sqlFile = migration.migrationDirectory().toPath()
.resolve("mysql/1.2__dropsFor_1.1.sql");
assertThat(sqlFile).isNotEmptyFile();
assertThat(Files.readAllLines(sqlFile, StandardCharsets.UTF_8))
.contains("CALL usp_ebean_drop_column('migtest_e_basic', 'status2');")
.contains("CALL usp_ebean_drop_column('migtest_e_basic', 'description');");
}
}
@@ -1,89 +0,0 @@
package misc.migration.mysql_v1_0;
import io.ebean.annotation.DbDefault;
import io.ebean.annotation.EnumValue;
import io.ebean.annotation.NotNull;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.Size;
@Entity
@Table(name = "migtest_e_basic")
public class EBasic {
public enum Status {
@EnumValue("N")
NEW,
@EnumValue("A")
ACTIVE,
@EnumValue("I")
INACTIVE,
}
@Id
Integer id;
Status status;
@DbDefault("N")
@NotNull
Status status2;
@Size(max=127)
String name;
@Size(max=127)
String description;
public EBasic() {
}
public EBasic(String name) {
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Status getStatus2() {
return status2;
}
public void setStatus2(final Status status2) {
this.status2 = status2;
}
}
@@ -1,64 +0,0 @@
package misc.migration.mysql_v1_1;
import io.ebean.annotation.EnumValue;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.Size;
@Entity
@Table(name = "migtest_e_basic")
public class EBasic {
public enum Status {
@EnumValue("N")
NEW,
@EnumValue("A")
ACTIVE,
@EnumValue("I")
INACTIVE,
}
@Id
Integer id;
Status status;
@Size(max=127)
String name;
public EBasic() {
}
public EBasic(String name) {
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@@ -51,7 +51,8 @@ public class EBasic {
@Size(max=127)
String name;
@DbMigration(preAlter = { "-- db2 does not support parial null indices :( - so we have to clean",
"update ${table} set status = 'N' where id = 1" }, platforms = Platform.DB2)
@DbMigration(preAlter = "-- rename all collisions")
@Column(unique = true)
@Size(max=127)
@@ -2,9 +2,11 @@ package misc.migration.v1_1;
import io.ebean.annotation.DbDefault;
import io.ebean.annotation.DbMigration;
import io.ebean.annotation.History;
import io.ebean.annotation.HistoryExclude;
import io.ebean.annotation.NotNull;
import io.ebean.annotation.Platform;
import javax.persistence.Entity;
import javax.persistence.Id;
@@ -20,6 +22,13 @@ public class EHistory2 {
Integer id;
@NotNull
// see: https://mariadb.com/de/resources/blog/use-cases-for-mariadb-data-versioning/
@DbMigration(preAlter = {
"SET @@system_versioning_alter_history = 1",
"update ${table} set ${column} = 'unknown' where ${column} is null"}, platforms = Platform.MARIADB)
// other platforms
@DbMigration(preAlter = "update ${table} set ${column} = 'unknown' where ${column} is null")
@DbDefault("unknown")
String testString;
@@ -1,5 +1,6 @@
package misc.migration.v1_1;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
@@ -18,6 +19,9 @@ public class MtmMaster {
@ManyToMany
List<MtmChild> children;
@ElementCollection
List<String> phoneNumbers;
public Long getId() {
return id;
}
@@ -199,14 +199,16 @@ datasource.hana.url=jdbc:sap://hxehost:39013/?databaseName=HXE
# parameters for migration test
datasource.migrationtest.username=SA
datasource.migrationtest.password=SA
datasource.migrationtest.url=jdbc:h2:mem:migration
datasource.migrationtest.url=jdbc:h2:mem:migration;NON_KEYWORDS=KEY,VALUE
ebean.migrationtest.applyPrefix=V
ebean.migrationtest.ddl.generate=false
ebean.migrationtest.ddl.run=false
ebean.migrationtest.ddl.header=-- Migrationscripts for ebean unittest
ebean.migrationtest.migration.appName=migrationtest
ebean.migrationtest.migration.migrationPath=dbmigration/migrationtest
ebean.migrationtest.migration.migrationPath=migrationtest/dbmigration
ebean.migrationtest.migration.strict=true
dbmigration.platform.mariadb.useMigrationStoredProcedures=true
dbmigration.platform.mysql.useMigrationStoredProcedures=true
# parameters for migration test
datasource.migrationtest-history.username=SA
@@ -217,5 +219,5 @@ ebean.migrationtest-history.ddl.generate=false
ebean.migrationtest-history.ddl.run=false
ebean.migrationtest-history.ddl.header=-- Migrationscripts for ebean unittest DbMigrationDropHistoryTest
ebean.migrationtest-history.migration.appName=migrationtest-history
ebean.migrationtest-history.migration.migrationPath=dbmigration/migrationtest-history
ebean.migrationtest-history.migration.migrationPath=migrationtest-history/dbmigration
ebean.migrationtest-history.migration.strict=true
@@ -0,0 +1,176 @@
-- Migrationscripts for ebean unittest
-- apply changes
create table migtest_ckey_assoc (
id integer auto_increment not null,
assoc_one varchar(255),
constraint pk_migtest_ckey_assoc primary key (id)
);
create table migtest_ckey_detail (
id integer auto_increment not null,
something varchar(255),
constraint pk_migtest_ckey_detail primary key (id)
);
create table migtest_ckey_parent (
one_key integer not null,
two_key varchar(127) not null,
name varchar(255),
version integer not null,
constraint pk_migtest_ckey_parent primary key (one_key,two_key)
);
create table migtest_fk_cascade (
id bigint auto_increment not null,
one_id bigint,
constraint pk_migtest_fk_cascade primary key (id)
);
create table migtest_fk_cascade_one (
id bigint auto_increment not null,
constraint pk_migtest_fk_cascade_one primary key (id)
);
create table migtest_fk_none (
id bigint auto_increment not null,
one_id bigint,
constraint pk_migtest_fk_none primary key (id)
);
create table migtest_fk_none_via_join (
id bigint auto_increment not null,
one_id bigint,
constraint pk_migtest_fk_none_via_join primary key (id)
);
create table migtest_fk_one (
id bigint auto_increment not null,
constraint pk_migtest_fk_one primary key (id)
);
create table migtest_fk_set_null (
id bigint auto_increment not null,
one_id bigint,
constraint pk_migtest_fk_set_null primary key (id)
);
create table migtest_e_basic (
id integer auto_increment not null,
status varchar(1),
status2 varchar(1) default 'N' not null,
name varchar(127),
description varchar(127),
some_date datetime(6),
old_boolean tinyint(1) default 0 not null,
old_boolean2 tinyint(1),
eref_id integer,
indextest1 varchar(127),
indextest2 varchar(127),
indextest3 varchar(127),
indextest4 varchar(127),
indextest5 varchar(127),
indextest6 varchar(127),
user_id integer not null,
constraint uq_migtest_e_basic_indextest2 unique (indextest2),
constraint uq_migtest_e_basic_indextest6 unique (indextest6),
constraint pk_migtest_e_basic primary key (id)
);
create table migtest_e_enum (
id integer auto_increment not null,
test_status varchar(1),
constraint pk_migtest_e_enum primary key (id)
);
create table migtest_e_history (
id integer auto_increment not null,
test_string varchar(255),
constraint pk_migtest_e_history primary key (id)
);
create table migtest_e_history2 (
id integer auto_increment not null,
test_string varchar(255),
obsolete_string1 varchar(255),
obsolete_string2 varchar(255),
constraint pk_migtest_e_history2 primary key (id)
);
create table migtest_e_history3 (
id integer auto_increment not null,
test_string varchar(255),
constraint pk_migtest_e_history3 primary key (id)
);
create table migtest_e_history4 (
id integer auto_increment not null,
test_number integer,
constraint pk_migtest_e_history4 primary key (id)
);
create table migtest_e_history5 (
id integer auto_increment not null,
test_number integer,
constraint pk_migtest_e_history5 primary key (id)
);
create table migtest_e_history6 (
id integer auto_increment not null,
test_number1 integer,
test_number2 integer not null,
constraint pk_migtest_e_history6 primary key (id)
);
create table migtest_e_ref (
id integer auto_increment not null,
name varchar(127) not null,
constraint uq_migtest_e_ref_name unique (name),
constraint pk_migtest_e_ref primary key (id)
);
create table migtest_e_softdelete (
id integer auto_increment not null,
test_string varchar(255),
constraint pk_migtest_e_softdelete primary key (id)
);
create table migtest_mtm_c (
id integer auto_increment not null,
name varchar(255),
constraint pk_migtest_mtm_c primary key (id)
);
create table migtest_mtm_m (
id bigint auto_increment not null,
name varchar(255),
constraint pk_migtest_mtm_m primary key (id)
);
create table migtest_oto_child (
id integer auto_increment not null,
name varchar(255),
constraint pk_migtest_oto_child primary key (id)
);
create table migtest_oto_master (
id bigint auto_increment not null,
name varchar(255),
constraint pk_migtest_oto_master primary key (id)
);
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
create index ix_migtest_fk_cascade_one_id on migtest_fk_cascade (one_id);
alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict;
create index ix_migtest_fk_set_null_one_id on migtest_fk_set_null (one_id);
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict;
create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id);
alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict;
alter table migtest_e_history2 add system versioning;
alter table migtest_e_history3 add system versioning;
alter table migtest_e_history4 add system versioning;
alter table migtest_e_history5 add system versioning;
alter table migtest_e_history6 add system versioning;
@@ -0,0 +1,106 @@
-- Migrationscripts for ebean unittest
-- apply changes
create table migtest_e_user (
id integer auto_increment not null,
constraint pk_migtest_e_user primary key (id)
);
create table migtest_mtm_c_migtest_mtm_m (
migtest_mtm_c_id integer not null,
migtest_mtm_m_id bigint not null,
constraint pk_migtest_mtm_c_migtest_mtm_m primary key (migtest_mtm_c_id,migtest_mtm_m_id)
);
create table migtest_mtm_m_migtest_mtm_c (
migtest_mtm_m_id bigint not null,
migtest_mtm_c_id integer not null,
constraint pk_migtest_mtm_m_migtest_mtm_c primary key (migtest_mtm_m_id,migtest_mtm_c_id)
);
alter table migtest_ckey_detail add column one_key integer;
alter table migtest_ckey_detail add column two_key varchar(127);
alter table migtest_ckey_detail add constraint fk_migtest_ckey_detail_parent foreign key (one_key,two_key) references migtest_ckey_parent (one_key,two_key) on delete restrict on update restrict;
alter table migtest_ckey_parent add column assoc_id integer;
alter table migtest_fk_cascade drop foreign key fk_migtest_fk_cascade_one_id;
alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete restrict on update restrict;
alter table migtest_fk_none add constraint fk_migtest_fk_none_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict;
alter table migtest_fk_none_via_join add constraint fk_migtest_fk_none_via_join_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict;
alter table migtest_fk_set_null drop foreign key fk_migtest_fk_set_null_one_id;
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete restrict on update restrict;
update migtest_e_basic set status = 'A' where status is null;
alter table migtest_e_basic alter status set default 'A';
alter table migtest_e_basic modify status varchar(1) not null;
alter table migtest_e_basic alter status2 drop default;
alter table migtest_e_basic modify status2 varchar(127);
-- rename all collisions;
alter table migtest_e_basic add constraint uq_migtest_e_basic_description unique (description);
insert into migtest_e_user (id) select distinct user_id from migtest_e_basic;
alter table migtest_e_basic add constraint fk_migtest_e_basic_user_id foreign key (user_id) references migtest_e_user (id) on delete restrict on update restrict;
alter table migtest_e_basic modify user_id integer;
alter table migtest_e_basic add column new_string_field varchar(255) default 'foo''bar' not null;
alter table migtest_e_basic add column new_boolean_field tinyint(1) default 1 not null;
update migtest_e_basic set new_boolean_field = old_boolean;
alter table migtest_e_basic add column new_boolean_field2 tinyint(1) default 1 not null;
alter table migtest_e_basic add column progress integer default 0 not null;
alter table migtest_e_basic add column new_integer integer default 42 not null;
alter table migtest_e_basic drop index uq_migtest_e_basic_indextest2;
alter table migtest_e_basic drop index uq_migtest_e_basic_indextest6;
alter table migtest_e_basic add constraint uq_migtest_e_basic_status_indextest1 unique (status,indextest1);
alter table migtest_e_basic add constraint uq_migtest_e_basic_name unique (name);
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest4 unique (indextest4);
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique (indextest5);
alter table migtest_e_history modify test_string bigint;
alter table migtest_e_history comment = 'We have history now';
-- NOTE: table has @History - special migration may be necessary
update migtest_e_history2 set test_string = 'unknown' where test_string is null;
alter table migtest_e_history2 alter test_string set default 'unknown';
alter table migtest_e_history2 modify test_string varchar(255) not null;
alter table migtest_e_history2 add column test_string2 varchar(255);
alter table migtest_e_history2 add column test_string3 varchar(255) default 'unknown' not null;
alter table migtest_e_history2 add column new_column varchar(20);
alter table migtest_e_history4 modify test_number bigint;
alter table migtest_e_history5 add column test_boolean tinyint(1) default 0 not null;
-- NOTE: table has @History - special migration may be necessary
update migtest_e_history6 set test_number1 = 42 where test_number1 is null;
alter table migtest_e_history6 alter test_number1 set default 42;
alter table migtest_e_history6 modify test_number1 integer not null;
alter table migtest_e_history6 modify test_number2 integer;
alter table migtest_e_softdelete add column deleted tinyint(1) default 0 not null;
alter table migtest_oto_child add column master_id bigint;
create index ix_migtest_e_basic_indextest3 on migtest_e_basic (indextest3);
create index ix_migtest_e_basic_indextest6 on migtest_e_basic (indextest6);
drop index ix_migtest_e_basic_indextest1 on migtest_e_basic;
drop index ix_migtest_e_basic_indextest5 on migtest_e_basic;
create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c on migtest_mtm_c_migtest_mtm_m (migtest_mtm_c_id);
alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict;
create index ix_migtest_mtm_c_migtest_mtm_m_migtest_mtm_m on migtest_mtm_c_migtest_mtm_m (migtest_mtm_m_id);
alter table migtest_mtm_c_migtest_mtm_m add constraint fk_migtest_mtm_c_migtest_mtm_m_migtest_mtm_m foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict on update restrict;
create index ix_migtest_mtm_m_migtest_mtm_c_migtest_mtm_m on migtest_mtm_m_migtest_mtm_c (migtest_mtm_m_id);
alter table migtest_mtm_m_migtest_mtm_c add constraint fk_migtest_mtm_m_migtest_mtm_c_migtest_mtm_m foreign key (migtest_mtm_m_id) references migtest_mtm_m (id) on delete restrict on update restrict;
create index ix_migtest_mtm_m_migtest_mtm_c_migtest_mtm_c on migtest_mtm_m_migtest_mtm_c (migtest_mtm_c_id);
alter table migtest_mtm_m_migtest_mtm_c add constraint fk_migtest_mtm_m_migtest_mtm_c_migtest_mtm_c foreign key (migtest_mtm_c_id) references migtest_mtm_c (id) on delete restrict on update restrict;
create index ix_migtest_ckey_parent_assoc_id on migtest_ckey_parent (assoc_id);
alter table migtest_ckey_parent add constraint fk_migtest_ckey_parent_assoc_id foreign key (assoc_id) references migtest_ckey_assoc (id) on delete restrict on update restrict;
alter table migtest_oto_child add constraint fk_migtest_oto_child_master_id foreign key (master_id) references migtest_oto_master (id) on delete restrict on update restrict;
alter table migtest_e_history add system versioning;
lock tables migtest_e_history3 write;
unlock tables;
@@ -0,0 +1,14 @@
-- Migrationscripts for ebean unittest
-- apply changes
alter table migtest_e_basic drop column old_boolean;
alter table migtest_e_basic drop column old_boolean2;
alter table migtest_e_basic drop column eref_id;
alter table migtest_e_history2 drop column obsolete_string1;
alter table migtest_e_history2 drop column obsolete_string2;
drop table if exists migtest_e_ref;
drop sequence if exists migtest_e_ref_seq;
@@ -0,0 +1,61 @@
-- Migrationscripts for ebean unittest
-- apply changes
create table migtest_e_ref (
id integer auto_increment not null,
name varchar(127) not null,
constraint uq_migtest_e_ref_name unique (name),
constraint pk_migtest_e_ref primary key (id)
);
alter table migtest_ckey_detail drop foreign key fk_migtest_ckey_detail_parent;
alter table migtest_fk_cascade drop foreign key fk_migtest_fk_cascade_one_id;
alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict;
alter table migtest_fk_none drop foreign key fk_migtest_fk_none_one_id;
alter table migtest_fk_none_via_join drop foreign key fk_migtest_fk_none_via_join_one_id;
alter table migtest_fk_set_null drop foreign key fk_migtest_fk_set_null_one_id;
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict;
alter table migtest_e_basic alter status drop default;
alter table migtest_e_basic modify status varchar(1);
update migtest_e_basic set status2 = 'N' where status2 is null;
alter table migtest_e_basic alter status2 set default 'N';
alter table migtest_e_basic modify status2 varchar(1) not null;
alter table migtest_e_basic drop index uq_migtest_e_basic_description;
update migtest_e_basic set user_id = 23 where user_id is null;
alter table migtest_e_basic drop foreign key fk_migtest_e_basic_user_id;
alter table migtest_e_basic alter user_id set default 23;
alter table migtest_e_basic modify user_id integer not null;
alter table migtest_e_basic add column old_boolean tinyint(1) default 0 not null;
alter table migtest_e_basic add column old_boolean2 tinyint(1);
alter table migtest_e_basic add column eref_id integer;
alter table migtest_e_basic drop index uq_migtest_e_basic_status_indextest1;
alter table migtest_e_basic drop index uq_migtest_e_basic_name;
alter table migtest_e_basic drop index uq_migtest_e_basic_indextest4;
alter table migtest_e_basic drop index uq_migtest_e_basic_indextest5;
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest2 unique (indextest2);
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique (indextest6);
alter table migtest_e_history comment = '';
alter table migtest_e_history2 alter test_string drop default;
alter table migtest_e_history2 modify test_string varchar(255);
alter table migtest_e_history2 add column obsolete_string1 varchar(255);
alter table migtest_e_history2 add column obsolete_string2 varchar(255);
alter table migtest_e_history4 modify test_number integer;
alter table migtest_e_history6 alter test_number1 drop default;
alter table migtest_e_history6 modify test_number1 integer;
-- NOTE: table has @History - special migration may be necessary
update migtest_e_history6 set test_number2 = 7 where test_number2 is null;
alter table migtest_e_history6 alter test_number2 set default 7;
alter table migtest_e_history6 modify test_number2 integer not null;
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
drop index ix_migtest_e_basic_indextest3 on migtest_e_basic;
drop index ix_migtest_e_basic_indextest6 on migtest_e_basic;
create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id);
alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict;
lock tables migtest_e_history3 write;
unlock tables;
@@ -0,0 +1,35 @@
-- Migrationscripts for ebean unittest
-- apply changes
alter table migtest_ckey_detail drop column one_key;
alter table migtest_ckey_detail drop column two_key;
alter table migtest_ckey_parent drop column assoc_id;
alter table migtest_e_basic drop column new_string_field;
alter table migtest_e_basic drop column new_boolean_field;
alter table migtest_e_basic drop column new_boolean_field2;
alter table migtest_e_basic drop column progress;
alter table migtest_e_basic drop column new_integer;
alter table migtest_e_history2 drop column test_string2;
alter table migtest_e_history2 drop column test_string3;
alter table migtest_e_history2 drop column new_column;
alter table migtest_e_history5 drop column test_boolean;
alter table migtest_e_softdelete drop column deleted;
alter table migtest_oto_child drop column master_id;
drop table if exists migtest_e_user;
drop sequence if exists migtest_e_user_seq;
drop table if exists migtest_mtm_c_migtest_mtm_m;
drop table if exists migtest_mtm_m_migtest_mtm_c;
alter table migtest_e_history drop system versioning;
@@ -0,0 +1,7 @@
create or replace view order_agg_vw as
select d.order_id, sum(d.order_qty * d.unit_price) as order_total,
sum(d.ship_qty * d.unit_price) as ship_total
from o_order_detail d
group by d.order_id
@@ -0,0 +1,7 @@
1615386118, 1.0__initial.sql
1747697741, 1.1.sql
-1462014216, 1.2__dropsFor_1.1.sql
-1957738355, 1.3.sql
1081793242, 1.4__dropsFor_1.3.sql
561281075, R__order_views.sql
@@ -1,14 +1,14 @@
-- Migrationscripts for ebean unittest
-- apply changes
alter table migtest_e_basic drop column old_boolean;
CALL usp_ebean_drop_column('migtest_e_basic', 'old_boolean');
alter table migtest_e_basic drop column old_boolean2;
CALL usp_ebean_drop_column('migtest_e_basic', 'old_boolean2');
alter table migtest_e_basic drop column eref_id;
CALL usp_ebean_drop_column('migtest_e_basic', 'eref_id');
alter table migtest_e_history2 drop column obsolete_string1;
CALL usp_ebean_drop_column('migtest_e_history2', 'obsolete_string1');
alter table migtest_e_history2 drop column obsolete_string2;
CALL usp_ebean_drop_column('migtest_e_history2', 'obsolete_string2');
drop table if exists migtest_e_ref;
drop sequence if exists migtest_e_ref_seq;
@@ -1,32 +1,32 @@
-- Migrationscripts for ebean unittest
-- apply changes
alter table migtest_ckey_detail drop column one_key;
CALL usp_ebean_drop_column('migtest_ckey_detail', 'one_key');
alter table migtest_ckey_detail drop column two_key;
CALL usp_ebean_drop_column('migtest_ckey_detail', 'two_key');
alter table migtest_ckey_parent drop column assoc_id;
CALL usp_ebean_drop_column('migtest_ckey_parent', 'assoc_id');
alter table migtest_e_basic drop column new_string_field;
CALL usp_ebean_drop_column('migtest_e_basic', 'new_string_field');
alter table migtest_e_basic drop column new_boolean_field;
CALL usp_ebean_drop_column('migtest_e_basic', 'new_boolean_field');
alter table migtest_e_basic drop column new_boolean_field2;
CALL usp_ebean_drop_column('migtest_e_basic', 'new_boolean_field2');
alter table migtest_e_basic drop column progress;
CALL usp_ebean_drop_column('migtest_e_basic', 'progress');
alter table migtest_e_basic drop column new_integer;
CALL usp_ebean_drop_column('migtest_e_basic', 'new_integer');
alter table migtest_e_history2 drop column test_string2;
CALL usp_ebean_drop_column('migtest_e_history2', 'test_string2');
alter table migtest_e_history2 drop column test_string3;
CALL usp_ebean_drop_column('migtest_e_history2', 'test_string3');
alter table migtest_e_history2 drop column new_column;
CALL usp_ebean_drop_column('migtest_e_history2', 'new_column');
alter table migtest_e_history5 drop column test_boolean;
CALL usp_ebean_drop_column('migtest_e_history5', 'test_boolean');
alter table migtest_e_softdelete drop column deleted;
CALL usp_ebean_drop_column('migtest_e_softdelete', 'deleted');
alter table migtest_oto_child drop column master_id;
CALL usp_ebean_drop_column('migtest_oto_child', 'master_id');
drop table if exists migtest_e_user;
drop sequence if exists migtest_e_user_seq;
@@ -0,0 +1,48 @@
-- Inital script to create stored procedures etc for mysql platform
DROP PROCEDURE IF EXISTS usp_ebean_drop_foreign_keys;
delimiter $$
--
-- PROCEDURE: usp_ebean_drop_foreign_keys TABLE, COLUMN
-- deletes all constraints and foreign keys referring to TABLE.COLUMN
--
CREATE PROCEDURE usp_ebean_drop_foreign_keys(IN p_table_name VARCHAR(255), IN p_column_name VARCHAR(255))
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE c_fk_name CHAR(255);
DECLARE curs CURSOR FOR SELECT CONSTRAINT_NAME from information_schema.KEY_COLUMN_USAGE
WHERE TABLE_SCHEMA = DATABASE() and TABLE_NAME = p_table_name and COLUMN_NAME = p_column_name
AND REFERENCED_TABLE_NAME IS NOT NULL;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN curs;
read_loop: LOOP
FETCH curs INTO c_fk_name;
IF done THEN
LEAVE read_loop;
END IF;
SET @sql = CONCAT('ALTER TABLE ', p_table_name, ' DROP FOREIGN KEY ', c_fk_name);
PREPARE stmt FROM @sql;
EXECUTE stmt;
END LOOP;
CLOSE curs;
END
$$
DROP PROCEDURE IF EXISTS usp_ebean_drop_column;
delimiter $$
--
-- PROCEDURE: usp_ebean_drop_column TABLE, COLUMN
-- deletes the column and ensures that all indices and constraints are dropped first
--
CREATE PROCEDURE usp_ebean_drop_column(IN p_table_name VARCHAR(255), IN p_column_name VARCHAR(255))
BEGIN
CALL usp_ebean_drop_foreign_keys(p_table_name, p_column_name);
SET @sql = CONCAT('ALTER TABLE ', p_table_name, ' DROP COLUMN ', p_column_name);
PREPARE stmt FROM @sql;
EXECUTE stmt;
END
$$
@@ -1,7 +1,8 @@
1835064798, I__create_procs.sql
1615386118, 1.0__initial.sql
1747697741, 1.1.sql
-1462014216, 1.2__dropsFor_1.1.sql
-116088700, 1.2__dropsFor_1.1.sql
-1957738355, 1.3.sql
1081793242, 1.4__dropsFor_1.3.sql
1065918589, 1.4__dropsFor_1.3.sql
561281075, R__order_views.sql
@@ -3,17 +3,17 @@
drop view if exists migtest_e_history2_with_history;
-- apply changes
alter table migtest_e_basic drop column old_boolean;
CALL usp_ebean_drop_column('migtest_e_basic', 'old_boolean');
alter table migtest_e_basic drop column old_boolean2;
CALL usp_ebean_drop_column('migtest_e_basic', 'old_boolean2');
alter table migtest_e_basic drop column eref_id;
CALL usp_ebean_drop_column('migtest_e_basic', 'eref_id');
alter table migtest_e_history2 drop column obsolete_string1;
alter table migtest_e_history2_history drop column obsolete_string1;
CALL usp_ebean_drop_column('migtest_e_history2', 'obsolete_string1');
CALL usp_ebean_drop_column('migtest_e_history2_history', 'obsolete_string1');
alter table migtest_e_history2 drop column obsolete_string2;
alter table migtest_e_history2_history drop column obsolete_string2;
CALL usp_ebean_drop_column('migtest_e_history2', 'obsolete_string2');
CALL usp_ebean_drop_column('migtest_e_history2_history', 'obsolete_string2');
drop table if exists migtest_e_ref;
create view migtest_e_history2_with_history as select * from migtest_e_history2 union all select * from migtest_e_history2_history;
@@ -3,45 +3,45 @@
drop trigger migtest_e_history_history_upd;
drop trigger migtest_e_history_history_del;
drop view migtest_e_history_with_history;
alter table migtest_e_history drop column sys_period_start;
alter table migtest_e_history drop column sys_period_end;
CALL usp_ebean_drop_column('migtest_e_history', 'sys_period_start');
CALL usp_ebean_drop_column('migtest_e_history', 'sys_period_end');
drop table migtest_e_history_history;
drop view if exists migtest_e_history2_with_history;
drop view if exists migtest_e_history5_with_history;
-- apply changes
alter table migtest_ckey_detail drop column one_key;
CALL usp_ebean_drop_column('migtest_ckey_detail', 'one_key');
alter table migtest_ckey_detail drop column two_key;
CALL usp_ebean_drop_column('migtest_ckey_detail', 'two_key');
alter table migtest_ckey_parent drop column assoc_id;
CALL usp_ebean_drop_column('migtest_ckey_parent', 'assoc_id');
alter table migtest_e_basic drop column new_string_field;
CALL usp_ebean_drop_column('migtest_e_basic', 'new_string_field');
alter table migtest_e_basic drop column new_boolean_field;
CALL usp_ebean_drop_column('migtest_e_basic', 'new_boolean_field');
alter table migtest_e_basic drop column new_boolean_field2;
CALL usp_ebean_drop_column('migtest_e_basic', 'new_boolean_field2');
alter table migtest_e_basic drop column progress;
CALL usp_ebean_drop_column('migtest_e_basic', 'progress');
alter table migtest_e_basic drop column new_integer;
CALL usp_ebean_drop_column('migtest_e_basic', 'new_integer');
alter table migtest_e_history2 drop column test_string2;
alter table migtest_e_history2_history drop column test_string2;
CALL usp_ebean_drop_column('migtest_e_history2', 'test_string2');
CALL usp_ebean_drop_column('migtest_e_history2_history', 'test_string2');
alter table migtest_e_history2 drop column test_string3;
alter table migtest_e_history2_history drop column test_string3;
CALL usp_ebean_drop_column('migtest_e_history2', 'test_string3');
CALL usp_ebean_drop_column('migtest_e_history2_history', 'test_string3');
alter table migtest_e_history2 drop column new_column;
alter table migtest_e_history2_history drop column new_column;
CALL usp_ebean_drop_column('migtest_e_history2', 'new_column');
CALL usp_ebean_drop_column('migtest_e_history2_history', 'new_column');
alter table migtest_e_history5 drop column test_boolean;
alter table migtest_e_history5_history drop column test_boolean;
CALL usp_ebean_drop_column('migtest_e_history5', 'test_boolean');
CALL usp_ebean_drop_column('migtest_e_history5_history', 'test_boolean');
alter table migtest_e_softdelete drop column deleted;
CALL usp_ebean_drop_column('migtest_e_softdelete', 'deleted');
alter table migtest_oto_child drop column master_id;
CALL usp_ebean_drop_column('migtest_oto_child', 'master_id');
drop table if exists migtest_e_user;
drop table if exists migtest_mtm_c_migtest_mtm_m;
@@ -0,0 +1,48 @@
-- Inital script to create stored procedures etc for mysql platform
DROP PROCEDURE IF EXISTS usp_ebean_drop_foreign_keys;
delimiter $$
--
-- PROCEDURE: usp_ebean_drop_foreign_keys TABLE, COLUMN
-- deletes all constraints and foreign keys referring to TABLE.COLUMN
--
CREATE PROCEDURE usp_ebean_drop_foreign_keys(IN p_table_name VARCHAR(255), IN p_column_name VARCHAR(255))
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE c_fk_name CHAR(255);
DECLARE curs CURSOR FOR SELECT CONSTRAINT_NAME from information_schema.KEY_COLUMN_USAGE
WHERE TABLE_SCHEMA = DATABASE() and TABLE_NAME = p_table_name and COLUMN_NAME = p_column_name
AND REFERENCED_TABLE_NAME IS NOT NULL;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN curs;
read_loop: LOOP
FETCH curs INTO c_fk_name;
IF done THEN
LEAVE read_loop;
END IF;
SET @sql = CONCAT('ALTER TABLE ', p_table_name, ' DROP FOREIGN KEY ', c_fk_name);
PREPARE stmt FROM @sql;
EXECUTE stmt;
END LOOP;
CLOSE curs;
END
$$
DROP PROCEDURE IF EXISTS usp_ebean_drop_column;
delimiter $$
--
-- PROCEDURE: usp_ebean_drop_column TABLE, COLUMN
-- deletes the column and ensures that all indices and constraints are dropped first
--
CREATE PROCEDURE usp_ebean_drop_column(IN p_table_name VARCHAR(255), IN p_column_name VARCHAR(255))
BEGIN
CALL usp_ebean_drop_foreign_keys(p_table_name, p_column_name);
SET @sql = CONCAT('ALTER TABLE ', p_table_name, ' DROP COLUMN ', p_column_name);
PREPARE stmt FROM @sql;
EXECUTE stmt;
END
$$
@@ -1,7 +1,8 @@
1835064798, I__create_procs.sql
-1087663151, 1.0__initial.sql
880212944, 1.1.sql
1029390755, 1.2__dropsFor_1.1.sql
1922991807, 1.2__dropsFor_1.1.sql
-380371830, 1.3.sql
1085680731, 1.4__dropsFor_1.3.sql
-1139228843, 1.4__dropsFor_1.3.sql
561281075, R__order_views.sql