Skip to content

Commit 3d425d5

Browse files
HCK-14977: Custom scripts - regular model (#57)
* HCK-14977: Custom scripts - regular model * fix * fix * fix * backward compatibility * remove
1 parent 4eb9b52 commit 3d425d5

7 files changed

Lines changed: 418 additions & 23 deletions

File tree

forward_engineering/ddlProvider.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = (baseProvider, options, app) => {
2020
const { assignTemplates, compareGroupItems } = app.require('@hackolade/ddl-fe-utils');
2121
const { decorateDefault, decorateType, canBeNational, getSign, createGeneratedColumn, canHaveAutoIncrement } =
2222
require('./helpers/columnDefinitionHelper')(wrap);
23-
const { getTableName, getTableOptions, getPartitions, getViewData, getCharacteristics, escapeQuotes } =
23+
const { getTableName, getTableOptions, getPartitions, getViewData, getCharacteristics, escapeQuotes, wrapInTicks } =
2424
require('./helpers/general')(_, wrap);
2525
const { generateConstraintsString, foreignKeysToString, foreignActiveKeysToString, createKeyConstraint } =
2626
require('./helpers/constraintsHelper')({
@@ -36,7 +36,7 @@ module.exports = (baseProvider, options, app) => {
3636
const additionalOptions = getAdditionalOptions(options.additionalOptions);
3737

3838
return dropStatementProxy({ commentIfDeactivated })(additionalOptions.applyDropStatements, {
39-
createDatabase({
39+
createSchema({
4040
databaseName,
4141
ifNotExist,
4242
collation,
@@ -71,11 +71,11 @@ module.exports = (baseProvider, options, app) => {
7171
);
7272
},
7373

74-
dropDatabase(dropDbData) {
74+
dropSchema(dropDbData) {
7575
return assignTemplates(templates.dropDatabase, dropDbData);
7676
},
7777

78-
alterDatabase(alterDbData) {
78+
alterSchema(alterDbData) {
7979
const alterStatements = [];
8080
const databaseName = alterDbData.name;
8181

@@ -798,7 +798,7 @@ module.exports = (baseProvider, options, app) => {
798798
};
799799
},
800800

801-
hydrateDatabase(containerData, data) {
801+
hydrateSchema(containerData, data) {
802802
return {
803803
databaseName: containerData.name,
804804
ifNotExist: containerData.ifNotExist,
@@ -812,6 +812,11 @@ module.exports = (baseProvider, options, app) => {
812812
};
813813
},
814814

815+
// Keep it because it was used to hydrate `dbData` for the API
816+
hydrateDatabase(containerData, data) {
817+
return this.hydrateSchema(containerData, data);
818+
},
819+
815820
hydrateTableSpace(tableSpace) {
816821
return {
817822
name: tableSpace.name,
@@ -911,6 +916,14 @@ module.exports = (baseProvider, options, app) => {
911916
return statement;
912917
},
913918

919+
commentStatement(statement) {
920+
return commentIfDeactivated(statement, { isActivated: false });
921+
},
922+
923+
prepareName(name) {
924+
return wrapInTicks(name);
925+
},
926+
914927
hydrateUdf(udf) {
915928
return {
916929
name: udf.name,
@@ -948,13 +961,13 @@ module.exports = (baseProvider, options, app) => {
948961
};
949962
},
950963

951-
hydrateDropDatabase(containerData) {
964+
hydrateDropSchema(containerData) {
952965
return {
953966
name: containerData[0]?.name || '',
954967
};
955968
},
956969

957-
hydrateAlterDatabase({ containerData, compModeData }) {
970+
hydrateAlterSchema({ containerData, compModeData }) {
958971
const data = containerData[0] || {};
959972
const isCharacterSetModified = compModeData.new.characterSet !== compModeData.old.characterSet;
960973
const isCollationModified = compModeData.new.collation !== compModeData.old.collation;

forward_engineering/helpers/general.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ module.exports = (_, wrap) => {
6767
NDB: ['KEY_BLOCK_SIZE'],
6868
};
6969

70+
const wrapInTicks = name => `\`${name}\``;
71+
7072
const getTableName = (tableName, schemaName) => {
7173
if (schemaName) {
7274
return `\`${schemaName}\`.\`${tableName}\``;
@@ -328,5 +330,6 @@ module.exports = (_, wrap) => {
328330
getViewData,
329331
getCharacteristics,
330332
escapeQuotes,
333+
wrapInTicks,
331334
};
332335
};

localization/en.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,10 @@
158158
"MODAL_WINDOW___OPTIONS_DISPLAY_ERD_V_ENTITY_BOX_CONTENT": "Display of table box content",
159159
"MODAL_WINDOW___OPTIONS_DISPLAY_ERD_V_FIELDS": "Columns",
160160
"MODAL_WINDOW___OPTIONS_DISPLAY_REQUIRED_ATTRIBUTES": "Required columns",
161-
"MODAL_WINDOW___OPTIONS_DISPLAY_NULLABLE_ATTRIBUTES": "Nullable columns"
161+
"MODAL_WINDOW___OPTIONS_DISPLAY_NULLABLE_ATTRIBUTES": "Nullable columns",
162+
163+
"CUSTOM_SCRIPT_CONTAINER_VAR_NAME": "Database name",
164+
"CUSTOM_SCRIPT_CONTAINER_VAR": "databaseName",
165+
"CUSTOM_SCRIPT_ENTITY_VAR_NAME": "Table name",
166+
"CUSTOM_SCRIPT_ENTITY_VAR": "tableName"
162167
}

properties_pane/container_level/containerLevelConfig.json

Lines changed: 128 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* Copyright © 2016-2017 by IntegrIT S.A. dba Hackolade. All rights reserved.
33
*
44
* The copyright to the computer software herein is the property of IntegrIT S.A.
5-
* The software may be used and/or copied only with the written permission of
6-
* IntegrIT S.A. or in accordance with the terms and conditions stipulated in
7-
* the agreement/contract under which the software has been supplied.
5+
* The software may be used and/or copied only with the written permission of
6+
* IntegrIT S.A. or in accordance with the terms and conditions stipulated in
7+
* the agreement/contract under which the software has been supplied.
88

99

1010
In order to define custom properties for any object's properties pane, you may copy/paste from the following,
@@ -51,8 +51,8 @@ making sure that you maintain a proper JSON format.
5151
"propertyType": "checkbox"
5252
},
5353
// “groupInput” can have the following states - 0 items, 1 item, and many items.
54-
// “blockInput” has only 2 states - 0 items or 1 item.
55-
// This gives us an easy way to represent it as an object and not as an array internally which is beneficial for processing
54+
// “blockInput” has only 2 states - 0 items or 1 item.
55+
// This gives us an easy way to represent it as an object and not as an array internally which is beneficial for processing
5656
// and forward-engineering in particular.
5757
{
5858
"propertyName": "Block",
@@ -80,7 +80,7 @@ making sure that you maintain a proper JSON format.
8080
"propertyKeyword": "keyList",
8181
"propertyType": "fieldList",
8282
"template": "orderedList"
83-
},
83+
},
8484
{
8585
"propertyName": "List with attribute",
8686
"propertyKeyword": "keyListOrder",
@@ -792,6 +792,128 @@ making sure that you maintain a proper JSON format.
792792
"defaultValue": "No",
793793
"options": ["No", "Yes"]
794794
},
795+
{
796+
"propertyName": "Custom scripts",
797+
"propertyType": "block",
798+
"propertyKeyword": "customScripts",
799+
"propertyTooltip": "",
800+
"structure": [
801+
{
802+
"propertyName": "Before CREATE DATABASE",
803+
"propertyKeyword": "beforeCreateContainer",
804+
"propertyType": "block",
805+
"propertyTooltip": "",
806+
"structure": [
807+
{
808+
"propertyName": "Script",
809+
"propertyKeyword": "script",
810+
"propertyType": "details",
811+
"markdown": false,
812+
"template": "codeEditor",
813+
"templateOptions": {
814+
"editorDialect": "sql",
815+
"customScriptVariables": true
816+
}
817+
}
818+
]
819+
},
820+
{
821+
"propertyName": "After CREATE DATABASE",
822+
"propertyKeyword": "afterCreateContainer",
823+
"propertyType": "block",
824+
"propertyTooltip": "",
825+
"structure": [
826+
{
827+
"propertyName": "Script",
828+
"propertyKeyword": "script",
829+
"propertyType": "details",
830+
"markdown": false,
831+
"template": "codeEditor",
832+
"templateOptions": {
833+
"editorDialect": "sql",
834+
"customScriptVariables": true
835+
}
836+
}
837+
]
838+
},
839+
{
840+
"propertyName": "Before each CREATE TABLE",
841+
"propertyKeyword": "beforeCreateEntity",
842+
"propertyType": "block",
843+
"propertyTooltip": "",
844+
"structure": [
845+
{
846+
"propertyName": "Script",
847+
"propertyKeyword": "script",
848+
"propertyType": "details",
849+
"markdown": false,
850+
"template": "codeEditor",
851+
"templateOptions": {
852+
"editorDialect": "sql",
853+
"customScriptVariables": true
854+
}
855+
}
856+
]
857+
},
858+
{
859+
"propertyName": "After each CREATE TABLE",
860+
"propertyKeyword": "afterCreateEntity",
861+
"propertyType": "block",
862+
"propertyTooltip": "",
863+
"structure": [
864+
{
865+
"propertyName": "Script",
866+
"propertyKeyword": "script",
867+
"propertyType": "details",
868+
"markdown": false,
869+
"template": "codeEditor",
870+
"templateOptions": {
871+
"editorDialect": "sql",
872+
"customScriptVariables": true
873+
}
874+
}
875+
]
876+
},
877+
{
878+
"propertyName": "Before each CREATE VIEW",
879+
"propertyKeyword": "beforeCreateView",
880+
"propertyType": "block",
881+
"propertyTooltip": "",
882+
"structure": [
883+
{
884+
"propertyName": "Script",
885+
"propertyKeyword": "script",
886+
"propertyType": "details",
887+
"markdown": false,
888+
"template": "codeEditor",
889+
"templateOptions": {
890+
"editorDialect": "sql",
891+
"customScriptVariables": true
892+
}
893+
}
894+
]
895+
},
896+
{
897+
"propertyName": "After each CREATE VIEW",
898+
"propertyKeyword": "afterCreateView",
899+
"propertyType": "block",
900+
"propertyTooltip": "",
901+
"structure": [
902+
{
903+
"propertyName": "Script",
904+
"propertyKeyword": "script",
905+
"propertyType": "details",
906+
"markdown": false,
907+
"template": "codeEditor",
908+
"templateOptions": {
909+
"editorDialect": "sql",
910+
"customScriptVariables": true
911+
}
912+
}
913+
]
914+
}
915+
]
916+
},
795917
{
796918
"propertyName": "Remarks",
797919
"propertyKeyword": "comments",

properties_pane/entity_level/entityLevelConfig.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,52 @@ making sure that you maintain a proper JSON format.
14941494
}
14951495
}
14961496
},
1497+
{
1498+
"propertyName": "Custom scripts",
1499+
"propertyType": "block",
1500+
"propertyKeyword": "customScripts",
1501+
"propertyTooltip": "",
1502+
"structure": [
1503+
{
1504+
"propertyName": "Before CREATE TABLE",
1505+
"propertyKeyword": "beforeCreateEntity",
1506+
"propertyType": "block",
1507+
"propertyTooltip": "",
1508+
"structure": [
1509+
{
1510+
"propertyName": "Script",
1511+
"propertyKeyword": "script",
1512+
"propertyType": "details",
1513+
"markdown": false,
1514+
"template": "codeEditor",
1515+
"templateOptions": {
1516+
"editorDialect": "sql",
1517+
"customScriptVariables": true
1518+
}
1519+
}
1520+
]
1521+
},
1522+
{
1523+
"propertyName": "After CREATE TABLE",
1524+
"propertyKeyword": "afterCreateEntity",
1525+
"propertyType": "block",
1526+
"propertyTooltip": "",
1527+
"structure": [
1528+
{
1529+
"propertyName": "Script",
1530+
"propertyKeyword": "script",
1531+
"propertyType": "details",
1532+
"markdown": false,
1533+
"template": "codeEditor",
1534+
"templateOptions": {
1535+
"editorDialect": "sql",
1536+
"customScriptVariables": true
1537+
}
1538+
}
1539+
]
1540+
}
1541+
]
1542+
},
14971543
{
14981544
"propertyName": "Remarks",
14991545
"propertyKeyword": "comments",

0 commit comments

Comments
 (0)