oradm-to-gql 34.2.0-rc → 35.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oradm-to-gql",
3
- "version": "34.2.0-rc",
3
+ "version": "35.0.0",
4
4
  "description": "Oracle Data Modeler CSV Export to Apollo GraphQL Endpoint Generator",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -125,6 +125,7 @@ module.exports = function convertRowsToTableMap(
125
125
  refAssociation.name = pluralize.plural(refAssociation.name);
126
126
  }
127
127
 
128
+ // TODO: we could also obtain this info more reliably from the ODM XML file.
128
129
  if (_.endsWith(fkRelation.Relation_Name, "_cascade")) {
129
130
  tabAttr.referenceShouldCascade = true;
130
131
  }
@@ -133,6 +134,14 @@ module.exports = function convertRowsToTableMap(
133
134
  tabAttr.referenceShouldRestrict = true;
134
135
  }
135
136
 
137
+ if (_.endsWith(fkRelation.Relation_Name, "_noaction")) {
138
+ tabAttr.referenceShouldNoAction = true;
139
+ }
140
+
141
+ if (_.endsWith(fkRelation.Relation_Name, "_setdefault")) {
142
+ tabAttr.referenceShouldSetDefault = true;
143
+ }
144
+
136
145
  refModel.associations.push(refAssociation);
137
146
  tableMap[refDef.entityName] = refModel;
138
147
  }
@@ -0,0 +1,20 @@
1
+ const { each } = require("lodash");
2
+
3
+ function defaultBooleans(tableMap) {
4
+ each(tableMap, (tableDef) => {
5
+ if (tableDef.type !== "view") {
6
+ each(tableDef.attributes, (attrDef, attrName) => {
7
+ if (attrDef.dataType === "Boolean") {
8
+ attrDef.nullable = false;
9
+ if (!attrDef.defaultValue) {
10
+ attrDef.defaultValue = false;
11
+ }
12
+ }
13
+ });
14
+ }
15
+ });
16
+
17
+ return tableMap;
18
+ }
19
+
20
+ module.exports = { defaultBooleans };
@@ -7,6 +7,7 @@ const addTimestampColumns = require("./addTimestampColumns");
7
7
  const { addIndexes } = require("./addIndexes");
8
8
  const { processViews } = require("./views");
9
9
  const { mergeCommonTableMap } = require("./mergeCommonTableMap");
10
+ const { defaultBooleans } = require("./defaultBooleans");
10
11
 
11
12
  module.exports = function parseDatamodelCSV(
12
13
  csvPath,
@@ -46,6 +47,7 @@ module.exports = function parseDatamodelCSV(
46
47
  }
47
48
 
48
49
  tableMap = addIndexes(tableMap, opts);
50
+ tableMap = defaultBooleans(tableMap, opts);
49
51
  tableMap = applyNamingRules(tableMap, opts);
50
52
  tableMap = processViews(tableMap, opts);
51
53
  tableMap = populateRelationshipAttributes(tableMap, opts);
@@ -134,10 +134,13 @@ module.exports = function (
134
134
  if (attrName == "code") relSpec.onUpdate = "CASCADE";
135
135
  if (!attrDef.nullable || attrDef.referenceShouldCascade === true)
136
136
  relSpec.onDelete = "CASCADE";
137
- if (attrDef.referenceShouldRestrict === true) {
137
+ if (attrDef.referenceShouldNoAction === true)
138
+ relSpec.onDelete = "NO ACTION";
139
+ if (attrDef.referenceShouldRestrict === true)
138
140
  relSpec.onDelete = "RESTRICT";
139
- console.log("DEBUG:relSpec:", relSpec)
140
- }
141
+ if (attrDef.referenceShouldSetDefault === true)
142
+ relSpec.onDelete = "SET DEFAULT";
143
+
141
144
  knexSpec.relationships.push(relSpec);
142
145
  }
143
146
 
@@ -45,10 +45,17 @@ function createTables(db, tableSpecs, opts = {}) {
45
45
  if (colSpec.unique) {
46
46
  table.unique(colSpec.name);
47
47
  }
48
- if (colSpec.defaultValue) {
48
+ if (colSpec.type === "boolean") {
49
+ colSpec.defaultValue = colSpec.defaultValue || false;
50
+ }
51
+ if (colSpec.defaultValue || colSpec.defaultValue === false) {
49
52
  let defaultValue = colSpec.defaultValue;
50
53
  if (colSpec.type === "boolean") {
51
- if (defaultValue === "false" || defaultValue === "0") {
54
+ if (
55
+ defaultValue === "false" ||
56
+ defaultValue === "0" ||
57
+ defaultValue === false
58
+ ) {
52
59
  defaultValue = false;
53
60
  } else {
54
61
  defaultValue = true;