Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different ColumnDefinition for different platforms #62

Merged
merged 4 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.ebeaninternal.dbmigration.ddlgeneration.platform;

import io.ebean.annotation.ConstraintMode;
import io.ebean.annotation.Platform;
import io.ebean.config.DatabaseConfig;
import io.ebean.config.DbConstraintNaming;
import io.ebean.config.dbplatform.DatabasePlatform;
Expand All @@ -24,6 +25,7 @@
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Locale;

/**
* Controls the DDL generation for a specific database platform.
Expand Down Expand Up @@ -317,12 +319,32 @@ public String convert(String type) {
if (type == null) {
return null;
}

type = extract(type);

if (type.contains("[]")) {
return convertArrayType(type);
}
return typeConverter.convert(type);
}

// if columnType is different for different platforms, use pattern
// @Column(columnDefinition = PLATFORM1;DEFINITION1;PLATFORM2;DEFINITON2;DEFINITON-DEFAULT)
// e.g. @Column(columnDefinition = "db2;blob(64M);sqlserver,h2;varchar(227);varchar(127)")
private String extract(String type) {
String[] tmp = type.split(";");
assert tmp.length % 2 == 1;
for (int i = 0; i < tmp.length - 2; i+=2) {
String[] platforms = tmp[i].split(",");
for (String plat : platforms) {
if (platform.isPlatform(Platform.valueOf(plat.toUpperCase(Locale.ENGLISH)))) {
return tmp[i+1];
}
}
}
return tmp[tmp.length-1]; // else
}

/**
* Convert the logical array type to a db platform specific type to support the array data.
*/
Expand Down
4 changes: 4 additions & 0 deletions ebean-test/src/test/java/misc/migration/v1_0/EBasic.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.ebean.annotation.NotNull;
import io.ebean.annotation.Tablespace;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
Expand Down Expand Up @@ -44,6 +45,9 @@ public enum Status {
@Size(max=127)
String description;

@Column(columnDefinition = "db2;blob(64M);sqlserver,h2;varchar(227);varchar(127)")
String description2;

Timestamp someDate;

boolean old_boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ create table migtest_e_basic (
status2 varchar(1) default 'N' not null,
name varchar(127),
description varchar(127),
description2 blob(64M),
some_date timestamp,
old_boolean boolean default false not null,
old_boolean2 boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-- Migrationscripts for ebean unittest
-- apply changes
alter table migtest_e_basic drop column description2;

alter table migtest_e_basic drop column old_boolean;

alter table migtest_e_basic drop column old_boolean2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-1602289007, I__create_tablespaces.sql
999346633, 1.0__initial.sql
1822640619, 1.0__initial.sql
2079409430, 1.1.sql
1091886546, 1.2__dropsFor_1.1.sql
327260977, 1.2__dropsFor_1.1.sql
-1291483335, 1.3.sql
1293885677, 1.4__dropsFor_1.3.sql
-133543359, R__db2_explain_tables.sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ create table migtest_e_basic (
status2 varchar(1) default 'N' not null,
name varchar(127),
description varchar(127),
description2 varchar(227),
some_date timestamp,
old_boolean boolean default false not null,
old_boolean2 boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
drop view if exists migtest_e_history2_with_history;

-- apply changes
alter table migtest_e_basic drop column description2;

alter table migtest_e_basic drop column old_boolean;

alter table migtest_e_basic drop column old_boolean2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-745768926, 1.0__initial.sql
-1018429770, 1.0__initial.sql
1409369419, 1.1.sql
1616986842, 1.2__dropsFor_1.1.sql
-1904864828, 1.2__dropsFor_1.1.sql
-1513154593, 1.3.sql
1549130952, 1.4__dropsFor_1.3.sql
783227075, R__multi_comments.sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ create column table migtest_e_basic (
status2 nvarchar(1) default 'N' not null,
name nvarchar(127),
description nvarchar(127),
description2 nvarchar(127),
some_date timestamp,
old_boolean boolean default false not null,
old_boolean2 boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-- Migrationscripts for ebean unittest
-- apply changes
CALL usp_ebean_drop_column('migtest_e_basic', 'description2');

CALL usp_ebean_drop_column('migtest_e_basic', 'old_boolean');

CALL usp_ebean_drop_column('migtest_e_basic', 'old_boolean2');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-1536923954, 1.0__initial.sql
-809467006, 1.0__initial.sql
-1152055114, 1.1.sql
562867593, 1.2__dropsFor_1.1.sql
1569252375, 1.2__dropsFor_1.1.sql
1566488731, 1.3.sql
201970227, 1.4__dropsFor_1.3.sql
1906063401, R__order_views_hana.sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ create table migtest_e_basic (
status2 varchar(1) default 'N' not null,
name varchar(127),
description varchar(127),
description2 varchar(127),
some_date timestamp,
old_boolean boolean default false not null,
old_boolean2 boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-- Migrationscripts for ebean unittest
-- apply changes
alter table migtest_e_basic drop column description2;

alter table migtest_e_basic drop column old_boolean;

alter table migtest_e_basic drop column old_boolean2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
2097980375, 1.0__initial.sql
1113607799, 1.0__initial.sql
-865579750, 1.1.sql
-1462014216, 1.2__dropsFor_1.1.sql
2029151368, 1.2__dropsFor_1.1.sql
-2039573992, 1.3.sql
-1763496614, 1.4__dropsFor_1.3.sql
861001272, R__order_views_hsqldb.sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ create table migtest_e_basic (
status2 varchar(1) default 'N' not null,
name varchar(127),
description varchar(127),
description2 varchar(127),
some_date datetime(6),
old_boolean tinyint(1) default 0 not null,
old_boolean2 tinyint(1),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-- Migrationscripts for ebean unittest
-- apply changes
CALL usp_ebean_drop_column('migtest_e_basic', 'description2');

CALL usp_ebean_drop_column('migtest_e_basic', 'old_boolean');

CALL usp_ebean_drop_column('migtest_e_basic', 'old_boolean2');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1835064798, I__create_procs.sql
1615386118, 1.0__initial.sql
629411155, 1.0__initial.sql
128637084, 1.1.sql
-116088700, 1.2__dropsFor_1.1.sql
-1078955818, 1.2__dropsFor_1.1.sql
-1957738355, 1.3.sql
930722740, 1.4__dropsFor_1.3.sql
561281075, R__order_views.sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<column name="status2" type="varchar(1)" defaultValue="'N'" notnull="true" checkConstraint="check ( status2 in ('N','A','I'))" checkConstraintName="ck_migtest_e_basic_status2"/>
<column name="name" type="varchar(127)"/>
<column name="description" type="varchar(127)"/>
<column name="description2" type="db2;blob(64M);sqlserver,h2;varchar(227);varchar(127)"/>
<column name="some_date" type="timestamp"/>
<column name="old_boolean" type="boolean" defaultValue="false" notnull="true"/>
<column name="old_boolean2" type="boolean"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
<dropIndex indexName="ix_migtest_oto_child_lowername" tableName="migtest_oto_child" platforms="POSTGRES"/>
</changeSet>
<changeSet type="pendingDrops">
<dropColumn columnName="description2" tableName="migtest_e_basic"/>
<dropColumn columnName="old_boolean" tableName="migtest_e_basic"/>
<dropColumn columnName="old_boolean2" tableName="migtest_e_basic"/>
<dropColumn columnName="eref_id" tableName="migtest_e_basic"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<migration xmlns="http://ebean-orm.github.io/xml/ns/dbmigration">
<changeSet type="apply" dropsFor="1.1">
<dropColumn columnName="description2" tableName="migtest_e_basic"/>
<dropColumn columnName="old_boolean" tableName="migtest_e_basic"/>
<dropColumn columnName="old_boolean2" tableName="migtest_e_basic"/>
<dropColumn columnName="eref_id" tableName="migtest_e_basic"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ create table migtest_e_basic (
status2 varchar(1) default 'N' not null,
name varchar(127),
description varchar(127),
description2 varchar(127),
some_date datetime(6),
old_boolean tinyint(1) default 0 not null,
old_boolean2 tinyint(1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
drop view if exists migtest_e_history2_with_history;

-- apply changes
CALL usp_ebean_drop_column('migtest_e_basic', 'description2');

CALL usp_ebean_drop_column('migtest_e_basic', 'old_boolean');

CALL usp_ebean_drop_column('migtest_e_basic', 'old_boolean2');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1835064798, I__create_procs.sql
1075178692, 1.0__initial.sql
-625233983, 1.0__initial.sql
-1627573867, 1.1.sql
1922991807, 1.2__dropsFor_1.1.sql
426154419, 1.2__dropsFor_1.1.sql
-380371830, 1.3.sql
-1373040825, 1.4__dropsFor_1.3.sql
561281075, R__order_views.sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ create table migtest_e_basic (
status2 varchar(1) default 'N' not null,
name varchar(127),
description varchar(127),
description2 varchar(127),
some_date datetime,
old_boolean tinyint(1) default 0 not null,
old_boolean2 tinyint(1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
drop view if exists migtest_e_history2_with_history;

-- apply changes
alter table migtest_e_basic drop column description2;

alter table migtest_e_basic drop column old_boolean;

alter table migtest_e_basic drop column old_boolean2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-1087663151, 1.0__initial.sql
-753661440, 1.0__initial.sql
-1627573867, 1.1.sql
1029390755, 1.2__dropsFor_1.1.sql
741043957, 1.2__dropsFor_1.1.sql
-380371830, 1.3.sql
-724776884, 1.4__dropsFor_1.3.sql
561281075, R__order_views.sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ create table migtest_e_basic (
status2 varchar2(1) default 'N' not null,
name varchar2(127),
description varchar2(127),
description2 varchar2(127),
some_date timestamp,
old_boolean number(1) default 0 not null,
old_boolean2 number(1),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-- Migrationscripts for ebean unittest
-- apply changes
alter table migtest_e_basic drop column description2;

alter table migtest_e_basic drop column old_boolean;

alter table migtest_e_basic drop column old_boolean2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1164675950, 1.0__initial.sql
-1818229777, 1.0__initial.sql
-411370666, 1.1.sql
238598298, 1.2__dropsFor_1.1.sql
521762942, 1.2__dropsFor_1.1.sql
483114276, 1.3.sql
-629809805, 1.4__dropsFor_1.3.sql
1357801733, R__oracle_only_views.sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ create table migtest_e_basic (
status2 varchar(1) default 'N' not null,
name varchar(127),
description varchar(127),
description2 varchar(127),
some_date timestamptz,
old_boolean boolean default false not null,
old_boolean2 boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
drop view if exists migtest_e_history2_with_history;

-- apply changes
alter table migtest_e_basic drop column description2;

alter table migtest_e_basic drop column old_boolean;

alter table migtest_e_basic drop column old_boolean2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1329543701, 1.0__initial.sql
1713516005, 1.0__initial.sql
1548995254, 1.1.sql
-1861367028, 1.2__dropsFor_1.1.sql
-1155149746, 1.2__dropsFor_1.1.sql
-1798982281, 1.3.sql
-1991941691, 1.4__dropsFor_1.3.sql
783227075, R__multi_comments.sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ create table migtest_e_basic (
status2 varchar(1) default 'N' not null,
name varchar(127),
description varchar(127),
description2 varchar(127),
some_date timestamp,
old_boolean int default 0 not null,
old_boolean2 int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-- Migrationscripts for ebean unittest
-- apply changes
alter table migtest_e_basic drop column description2;

alter table migtest_e_basic drop column old_boolean;

alter table migtest_e_basic drop column old_boolean2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1429491518, 1.0__initial.sql
1636161797, 1.0__initial.sql
-1974335860, 1.1.sql
1359055889, 1.2__dropsFor_1.1.sql
519662611, 1.2__dropsFor_1.1.sql
-1764531063, 1.3.sql
-1045594368, 1.4__dropsFor_1.3.sql
2034589659, R__order_views_sqlite.sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ create table migtest_e_basic (
status2 nvarchar(1) default 'N' not null,
name nvarchar(127),
description nvarchar(127),
description2 nvarchar(227),
some_date datetime2,
old_boolean bit default 0 not null,
old_boolean2 bit,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-- Migrationscripts for ebean unittest
-- apply changes
EXEC usp_ebean_drop_column migtest_e_basic, description2;

EXEC usp_ebean_drop_column migtest_e_basic, old_boolean;

EXEC usp_ebean_drop_column migtest_e_basic, old_boolean2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-2122378240, I__create_procs.sql
-1048913407, 1.0__initial.sql
-1036149520, 1.0__initial.sql
-898063858, 1.1.sql
-1805601919, 1.2__dropsFor_1.1.sql
1470614292, 1.2__dropsFor_1.1.sql
-1791137342, 1.3.sql
-1335541264, 1.4__dropsFor_1.3.sql
1607822082, R__order_views_mssql.sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ create table migtest_e_basic (
status2 varchar(1) default 'N' not null,
name varchar(127),
description varchar(127),
description2 varchar(127),
some_date timestamptz,
old_boolean boolean default false not null,
old_boolean2 boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
drop view if exists migtest_e_history2_with_history;

-- apply changes
alter table migtest_e_basic drop column description2;

alter table migtest_e_basic drop column old_boolean;

alter table migtest_e_basic drop column old_boolean2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-1449071956, 1.0__initial.sql
603721056, 1.0__initial.sql
1985413053, 1.1.sql
-1861367028, 1.2__dropsFor_1.1.sql
-1155149746, 1.2__dropsFor_1.1.sql
2034977550, 1.3.sql
-1991941691, 1.4__dropsFor_1.3.sql
561281075, R__order_views.sql
Expand Down
Loading