oradm-to-gql 35.1.0 → 35.1.2
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 +1 -1
- package/src/commands/table-map/generateTableMap.js +1 -5
- package/src/commands/table-map/index.js +1 -2
- package/src/data-lib-generator/templates/createEntity.njk +2 -2
- package/src/data-lib-generator/templates/updateEntity.njk +2 -2
- package/src/datamodel-csv-parser/addUpdatedByColumn.js +43 -0
- package/src/datamodel-csv-parser/index.js +5 -5
- package/src/datamodel-csv-parser/addUserColumn.js +0 -39
package/package.json
CHANGED
@@ -3,16 +3,12 @@ const path = require("path");
|
|
3
3
|
const fse = require("fs-extra");
|
4
4
|
|
5
5
|
module.exports = function generateTableMap(csvPath, outputDir, opts = {}) {
|
6
|
-
const { extend, timestamps, verbose, maxNameLength
|
6
|
+
const { extend, timestamps, verbose, maxNameLength } = opts;
|
7
7
|
|
8
8
|
let log = () => {};
|
9
9
|
if (verbose) log = console.log;
|
10
10
|
|
11
11
|
let parseOpts = { log, maxNameLength };
|
12
|
-
|
13
|
-
if (user) {
|
14
|
-
parseOpts.user = { modified: "updatedBy" };
|
15
|
-
}
|
16
12
|
|
17
13
|
if (timestamps) {
|
18
14
|
parseOpts.timestamps = { created: "createdAt", modified: "updatedAt" };
|
@@ -4,8 +4,7 @@ module.exports = {
|
|
4
4
|
command: "table-map <csvPath> <outputDir>",
|
5
5
|
options: {
|
6
6
|
"-v, --verbose": "Display verbose output",
|
7
|
-
"-t, --timestamps": "Add timestamp attributes to all models",
|
8
|
-
"-u, --user": "Add updated by attribute to all models",
|
7
|
+
"-t, --timestamps": "Add timestamp attributes to all models",
|
9
8
|
"-x, --extend <extendTableMap>": "Uses the specified module to extend the table map"
|
10
9
|
},
|
11
10
|
action: generateTableMap
|
@@ -40,7 +40,7 @@ async function create{{makePlural(entityName)}}(createRecords, trx, opts){
|
|
40
40
|
let modifiedUser = undefined;
|
41
41
|
|
42
42
|
if(this.context.req.user){
|
43
|
-
modifiedUser =
|
43
|
+
modifiedUser = this.context.req.user.id;
|
44
44
|
}
|
45
45
|
|
46
46
|
records.forEach((rec) => {
|
@@ -58,7 +58,7 @@ async function create{{makePlural(entityName)}}(createRecords, trx, opts){
|
|
58
58
|
//set timestamps
|
59
59
|
rec.{{attrDef.name}} = createdTimestamp;
|
60
60
|
{% endif %}
|
61
|
-
{% if attrDef.
|
61
|
+
{% if attrDef.updatedBy == 'modified' %}
|
62
62
|
//set modified user
|
63
63
|
rec.{{attrDef.name}} = modifiedUser;
|
64
64
|
{% endif %}
|
@@ -42,7 +42,7 @@ async function update{{makePlural(entityName)}}(updateRecords, fkFilter, trx, op
|
|
42
42
|
let modifiedUser = undefined;
|
43
43
|
|
44
44
|
if(this.context.req.user){
|
45
|
-
modifiedUser =
|
45
|
+
modifiedUser = this.context.req.user.id;
|
46
46
|
}
|
47
47
|
|
48
48
|
return Promise.each(records, async (updateRecord) =>
|
@@ -108,7 +108,7 @@ async function update{{makePlural(entityName)}}(updateRecords, fkFilter, trx, op
|
|
108
108
|
{% if attrDef.timestamp == 'modified' %}
|
109
109
|
values.{{attrDef.columnName}} = modifiedTimestamp;
|
110
110
|
{% endif %}
|
111
|
-
{% if attrDef.
|
111
|
+
{% if attrDef.updatedBy == 'modified' %}
|
112
112
|
values.{{attrDef.columnName}} = modifiedUser;
|
113
113
|
{% endif %}
|
114
114
|
{% endfor %}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
const { each } = require("lodash");
|
2
|
+
|
3
|
+
module.exports = function addUpdatedByColumn(tableMap, updatedBy, opts) {
|
4
|
+
opts = opts || {};
|
5
|
+
each(tableMap, (table, tableName) => {
|
6
|
+
if (table.type !== "view") {
|
7
|
+
if (updatedBy.modified) {
|
8
|
+
var modifiedColName = updatedBy.modified;
|
9
|
+
if (typeof table.attributes[modifiedColName] === "undefined") {
|
10
|
+
table.attributes[modifiedColName] = {
|
11
|
+
name: modifiedColName,
|
12
|
+
columnName: modifiedColName,
|
13
|
+
dataType: "UUID",
|
14
|
+
isPrimaryKey: false,
|
15
|
+
isForeignKey: true,
|
16
|
+
size: "",
|
17
|
+
precision: "",
|
18
|
+
scale: "",
|
19
|
+
nullable: true,
|
20
|
+
referenceName: "User",
|
21
|
+
relAttrName: "user",
|
22
|
+
referenceKey: "id",
|
23
|
+
referenceIdentifying: false,
|
24
|
+
referenceIsPlural: true,
|
25
|
+
fkName: "modifiedBy_usrId_fk"
|
26
|
+
};
|
27
|
+
} else {
|
28
|
+
if (updatedBy.errorOnConflict) {
|
29
|
+
throw new Error(
|
30
|
+
`[DM GEN ERROR] updatedBy ${modifiedColName} field already exists on ${tableName}. Unset updatedBy.errorOnConflict to warn instead of throwing.`
|
31
|
+
);
|
32
|
+
} else {
|
33
|
+
console.warn(
|
34
|
+
`[DM GEN WARNING] updatedBy ${modifiedColName} field already exists on ${tableName}. Set updatedBy.errorOnConflict throw an error instead of warning`
|
35
|
+
);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
});
|
41
|
+
|
42
|
+
return tableMap;
|
43
|
+
};
|
@@ -4,7 +4,7 @@ const applyNamingRules = require("./applyNamingRules");
|
|
4
4
|
const populateRelationshipAttributes = require("./populateRelationshipAttributes");
|
5
5
|
const extendTableMap = require("./extendTableMap");
|
6
6
|
const addTimestampColumns = require("./addTimestampColumns");
|
7
|
-
const
|
7
|
+
const addUpdatedByColumn = require("./addUpdatedByColumn");
|
8
8
|
const { addIndexes } = require("./addIndexes");
|
9
9
|
const { processViews } = require("./views");
|
10
10
|
const { mergeCommonTableMap } = require("./mergeCommonTableMap");
|
@@ -45,10 +45,10 @@ module.exports = function parseDatamodelCSV(
|
|
45
45
|
if (opts.timestamps) {
|
46
46
|
tableMap = addTimestampColumns(tableMap, opts.timestamps, opts);
|
47
47
|
}
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
|
49
|
+
if (opts.updatedBy) {
|
50
|
+
tableMap = addUpdatedByColumn(tableMap, opts.updatedBy, opts);
|
51
|
+
}
|
52
52
|
|
53
53
|
tableMap = addIndexes(tableMap, opts);
|
54
54
|
tableMap = applyNamingRules(tableMap, opts);
|
@@ -1,39 +0,0 @@
|
|
1
|
-
const { each } = require("lodash");
|
2
|
-
|
3
|
-
module.exports = function addUserColumn(tableMap, user, opts) {
|
4
|
-
opts = opts || {};
|
5
|
-
each(tableMap, (table, tableName) => {
|
6
|
-
if (table.type !== "view") {
|
7
|
-
if (user.modified) {
|
8
|
-
var modifiedColName = user.modified;
|
9
|
-
if (typeof table.attributes[modifiedColName] === "undefined") {
|
10
|
-
table.attributes[modifiedColName] = {
|
11
|
-
name: modifiedColName,
|
12
|
-
dataType: "ORDDOC",
|
13
|
-
isPrimaryKey: false,
|
14
|
-
isForeignKey: false,
|
15
|
-
size: "",
|
16
|
-
precision: "",
|
17
|
-
scale: "",
|
18
|
-
nullable: true,
|
19
|
-
unique: false,
|
20
|
-
columnName: modifiedColName,
|
21
|
-
user: "modified",
|
22
|
-
};
|
23
|
-
} else {
|
24
|
-
if (user.errorOnConflict) {
|
25
|
-
throw new Error(
|
26
|
-
`[DM GEN ERROR] user ${modifiedColName} field already exists on ${tableName}. Unset user.errorOnConflict to warn instead of throwing.`
|
27
|
-
);
|
28
|
-
} else {
|
29
|
-
console.warn(
|
30
|
-
`[DM GEN WARNING] user ${modifiedColName} field already exists on ${tableName}. Set user.errorOnConflict throw an error instead of warning`
|
31
|
-
);
|
32
|
-
}
|
33
|
-
}
|
34
|
-
}
|
35
|
-
}
|
36
|
-
});
|
37
|
-
|
38
|
-
return tableMap;
|
39
|
-
};
|