mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Fix: HANA always requires stored procedures (similar to SqlServer), Fix: default value on intermediate alters
This commit is contained in:
@@ -92,4 +92,8 @@ public class HanaPlatform extends DatabasePlatform {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseMigrationStoredProcedures() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-5
@@ -57,19 +57,21 @@ public abstract class AbstractHanaDdl extends PlatformDdl {
|
||||
if (isNumberType(currentType)) {
|
||||
// numbers can always be converted to decimal
|
||||
buffer.append("alter table ").append(tableName).append(" ").append(alterColumn).append(" ").append(columnName)
|
||||
.append(" decimal ").append(defaultValueClause).append(notnullClause).append(alterColumnSuffix)
|
||||
.endOfStatement();
|
||||
.append(" decimal ").append(notnullClause).append(alterColumnSuffix)
|
||||
.endOfStatement();
|
||||
|
||||
} else if (isStringType(currentType)) {
|
||||
// strings can always be converted to nclob
|
||||
// Note: we do not add default clause here to avoid error[SAP DBTech JDBC: [336]: invalid default value:
|
||||
// default value cannot be created on column of data type NCLOB
|
||||
buffer.append("alter table ").append(tableName).append(" ").append(alterColumn).append(" ").append(columnName)
|
||||
.append(" nclob ").append(defaultValueClause).append(notnullClause).append(alterColumnSuffix)
|
||||
.endOfStatement();
|
||||
.append(" nclob").append(notnullClause).append(alterColumnSuffix)
|
||||
.endOfStatement();
|
||||
}
|
||||
}
|
||||
|
||||
buffer.append("alter table ").append(tableName).append(" ").append(alterColumn).append(" ").append(columnName)
|
||||
.append(" ").append(type).append(defaultValueClause).append(notnullClause).append(alterColumnSuffix);
|
||||
.append(" ").append(type).append(defaultValueClause).append(notnullClause).append(alterColumnSuffix);
|
||||
|
||||
return buffer.getBuffer();
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ declare exit handler for sql_error_code 397 begin end;
|
||||
exec 'alter table migtest_e_basic drop constraint ck_migtest_e_basic_status2';
|
||||
end;
|
||||
$$;
|
||||
alter table migtest_e_basic alter ( status2 nclob default 'N' not null);
|
||||
alter table migtest_e_basic alter ( status2 nclob not null);
|
||||
alter table migtest_e_basic alter ( status2 nvarchar(1) default 'N' not null);
|
||||
alter table migtest_e_basic add constraint ck_migtest_e_basic_status2 check ( status2 in ('N','A','I'));
|
||||
delimiter $$
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
-- Inital script to create stored procedures etc for the hana platform
|
||||
delimiter $$
|
||||
--
|
||||
-- PROCEDURE: usp_ebean_drop_foreign_keys TABLE, COLUMN
|
||||
-- deletes all constraints and foreign keys referring to TABLE.COLUMN
|
||||
--
|
||||
CREATE OR REPLACE PROCEDURE usp_ebean_drop_foreign_keys(IN table_name NVARCHAR(256), IN column_name NVARCHAR(256))
|
||||
AS
|
||||
BEGIN
|
||||
DECLARE foreign_key_names TABLE(CONSTRAINT_NAME NVARCHAR(256), TABLE_NAME NVARCHAR(256));
|
||||
DECLARE i INT;
|
||||
|
||||
foreign_key_names = SELECT CONSTRAINT_NAME, TABLE_NAME FROM SYS.REFERENTIAL_CONSTRAINTS WHERE SCHEMA_NAME=CURRENT_SCHEMA AND TABLE_NAME=UPPER(:table_name) AND COLUMN_NAME=UPPER(:column_name);
|
||||
|
||||
FOR I IN 1 .. RECORD_COUNT(:foreign_key_names) DO
|
||||
EXEC 'ALTER TABLE "' || ESCAPE_DOUBLE_QUOTES(:foreign_key_names.TABLE_NAME[i]) || '" DROP CONSTRAINT "' || ESCAPE_DOUBLE_QUOTES(:foreign_key_names.CONSTRAINT_NAME[i]) || '"';
|
||||
END FOR;
|
||||
|
||||
END;
|
||||
$$
|
||||
|
||||
delimiter $$
|
||||
--
|
||||
-- PROCEDURE: usp_ebean_drop_column TABLE, COLUMN
|
||||
-- deletes the column and ensures that all indices and constraints are dropped first
|
||||
--
|
||||
CREATE OR REPLACE PROCEDURE usp_ebean_drop_column(IN table_name NVARCHAR(256), IN column_name NVARCHAR(256))
|
||||
AS
|
||||
BEGIN
|
||||
CALL usp_ebean_drop_foreign_keys(table_name, column_name);
|
||||
EXEC 'ALTER TABLE "' || UPPER(ESCAPE_DOUBLE_QUOTES(table_name)) || '" DROP ("' || UPPER(ESCAPE_DOUBLE_QUOTES(column_name)) || '")';
|
||||
END;
|
||||
$$
|
||||
@@ -1,7 +1,8 @@
|
||||
-745347271, I__create_procs.sql
|
||||
513351138, 1.0__initial.sql
|
||||
-1152055114, 1.1.sql
|
||||
1830946249, 1.2__dropsFor_1.1.sql
|
||||
1073423108, 1.3.sql
|
||||
744723875, 1.3.sql
|
||||
201970227, 1.4__dropsFor_1.3.sql
|
||||
1906063401, R__order_views_hana.sql
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
# Note: You need a running docker container. See howto-test.md for details
|
||||
datasource.default=hana
|
||||
datasource.hana.username=SYSTEM
|
||||
datasource.hana.password=VeryVerySecret#1234
|
||||
datasource.hana.url=jdbc:sap://localhost:39041/
|
||||
|
||||
@@ -43,3 +43,25 @@ Maven
|
||||
|
||||
Use the `-Dprops.file` parameter to start the test cases for a certain platform.
|
||||
|
||||
SAP HANA
|
||||
--------
|
||||
To set up a SAP HANA container, you may need a docker account to download the image
|
||||
|
||||
1. Remove any existing HANA container with `docker rm hana`
|
||||
|
||||
2. Create an empty directory (e.g. `/tmp/hana`)
|
||||
|
||||
3. Create a `settings.json` file with content `{ "master_password": "VeryVerySecret#1234" }` in that directory
|
||||
|
||||
4. Run the container, e.g with this command:
|
||||
|
||||
```
|
||||
docker run -p 39013:39013 -p 39017:39017 -p 39041-39045:39041-39045 -p 1128-1129:1128-1129 -p 59013-59014:59013-59014 \
|
||||
-v /tmp/hana:/hana/mounts \
|
||||
--ulimit nofile=1048576:1048576 --sysctl kernel.shmmax=1073741824
|
||||
--sysctl net.ipv4.ip_local_port_range="40000 60999" --sysctl kernel.shmall=8388608 \
|
||||
--name "hana" store/saplabs/hanaexpress:2.00.045.00.20200121.1 \
|
||||
--passwords-url file:///hana/mounts/settings.json --agree-to-sap-license
|
||||
```
|
||||
|
||||
You can optionally add the `-d` parameter. Note, if you re-run that command, the best advice is to clear the data directory and recreate the settings.json file
|
||||
|
||||
Reference in New Issue
Block a user