Skip to content

Commit 3431d05

Browse files
author
Giovanni Garufi
committed
Updated according to review
1 parent 141982d commit 3431d05

File tree

5 files changed

+119
-93
lines changed

5 files changed

+119
-93
lines changed

AbstractSQLCompiler.js

Lines changed: 87 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AbstractSQLCompiler.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AbstractSQLCompiler.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,10 @@ const compileSchema = (abstractSqlModel: AbstractSqlModel, engine: Engines, ifNo
379379
}
380380

381381
const generateSplit = <T>(src:Array<T>, dst: Array<T>, matchFn: MatchFn<T>): Split<T> => {
382-
let modified: Array<Pair<T>> = []
382+
const modified: Array<Pair<T>> = []
383383
return _.reduce(src, (acc, value) => {
384384
const match = matchFn(acc.inserted, value)
385-
if (_.isUndefined(match)) {
385+
if (match == null) {
386386
return acc
387387
} else {
388388
acc.inserted = _.without(acc.inserted, match)
@@ -406,7 +406,7 @@ const generateDiff = <T>(insFn: ToSQLFn<T>, delFn: ToSQLFn<T>, modFn: ToSQLFn<Pa
406406
.concat(_.map(split.deleted, delFn))
407407
.concat(_.map(split.inserted, insFn))
408408

409-
return _.reject(diff, _.isUndefined)
409+
return _.reject(diff, _.isNil)
410410
}
411411

412412
const diffFields = (src: AbstractSqlField[], dst: AbstractSqlField[], mappings: ResourceMap<string>, engine: Engines, ifNotExists: boolean) => {
@@ -422,20 +422,19 @@ const diffFields = (src: AbstractSqlField[], dst: AbstractSqlField[], mappings:
422422
}
423423

424424
const matchFn: MatchFn<AbstractSqlField> = (fieldArray, field) => {
425-
let match = _.find(fieldArray, { fieldName: field.fieldName })
426-
if (_.isUndefined(match)) {
425+
const match = _.find(fieldArray, { fieldName: field.fieldName })
426+
if (match != null) {
427+
return match
428+
}
429+
else {
427430
if (_.isString(mappings[field.fieldName])) {
428431
return _.find(fieldArray, { fieldName: mappings[field.fieldName] } )
429432
}
430-
} else {
431-
return match
432-
}
433+
}
433434
}
434435

435436
const insFn: ToSQLFn<AbstractSqlField> = (field) => {
436-
// Columns are inserted as NULL for the time being, this is because we have no sensible way to automatically assign a default value
437-
return 'ADD COLUMN ' + ifNotExistsStr + '"' + field.fieldName + '" ' + dataTypeGen(engine, field) + ';'
438-
437+
return 'ADD COLUMN ' + ifNotExistsStr + '"' + field.fieldName + '" ' + dataTypeGen(engine, field) + ';'
439438
}
440439

441440
const delFn: ToSQLFn<AbstractSqlField> = (field) => {
@@ -449,7 +448,7 @@ const diffFields = (src: AbstractSqlField[], dst: AbstractSqlField[], mappings:
449448
if (_.isEqual(_.omit(src, ['fieldName', 'references']), _.omit(dst, ['fieldName', 'references']))) {
450449
return 'RENAME COLUMN "' + src.fieldName + '" TO "' + dst.fieldName + '";'
451450
}
452-
throw Error(`Can not migrate pre-existing field ${src.fieldName} to ${dst.fieldName}`)
451+
throw Error(`Can not migrate pre-existing field ${src.fieldName} of type ${src.dataType} to ${dst.fieldName} of type ${dst.dataType}`)
453452
}
454453

455454
return generateDiff(insFn, delFn, modFn, matchFn, src, dst)
@@ -460,18 +459,21 @@ const diffSchemas = (src: AbstractSqlModel, dst: AbstractSqlModel, engine: Engin
460459
const dstSDM = mkSchemaDependencyMap(dst.tables, engine, ifNotExists).schemaDependencyMap
461460

462461
const matchFn:MatchFn<AbstractSqlTable> = (tables, srcTable) => {
463-
let match = _.find(tables, { name: srcTable.name })
464-
if (_.isUndefined(match)) {
462+
const match = _.find(tables, { name: srcTable.name })
463+
if (match != null) {
464+
return match
465+
} else {
465466
const relations = src.relationships[srcTable.name]
466-
if (!_.isUndefined(relations)) {
467+
if (relations == null) {
468+
return
469+
} else {
467470
return _.find(tables, (dstTable) => {
468-
let verb = dstTable.name.split('-').slice(1, -1).join(' ')
469-
return !_.isUndefined(relations[verb])
471+
const verb = dstTable.name.split('-').slice(1, -1).join(' ')
472+
return relations[verb] != null
470473
})
471474
}
472-
return relations
473-
}
474-
return match
475+
476+
}
475477
}
476478

477479
const insFn: ToSQLFn<AbstractSqlTable> = (table) => {
@@ -512,10 +514,8 @@ const diffSchemas = (src: AbstractSqlModel, dst: AbstractSqlModel, engine: Engin
512514
}
513515

514516
const extractMappings = (resource:string):[string, string] => {
515-
const resourceParts = resource.split('-')
516-
const subject = resourceParts[0]
517-
const rest = resourceParts.slice(1).join('-')
518-
return [subject, rest]
517+
const [ subject, ...rest ] = resource.split('-')
518+
return [ subject, rest.join('-') ]
519519
}
520520
const generateExport = (engine: Engines, ifNotExists: boolean) => {
521521
return {

AbstractSQLOptimiser.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,8 @@
11081108
this._pred(!_(duration).omit("negative").isEmpty());
11091109
return [ "Duration", duration ];
11101110
}
1111-
}), AbstractSQLOptimiser = exports.AbstractSQLOptimiser = AbstractSQLValidator._extend({
1111+
});
1112+
(exports.AbstractSQLOptimiser = AbstractSQLValidator._extend({
11121113
FieldNotEquals: function() {
11131114
var $elf = this, _fromIdx = this.input.idx, comp1, comp2;
11141115
this._form(function() {
@@ -1353,7 +1354,7 @@
13531354
},
13541355
Helped: function(disableMemoisationHack) {
13551356
var $elf = this, _fromIdx = this.input.idx;
1356-
this._pred(this.helped === !0);
1357+
this._pred(!0 === this.helped);
13571358
return this.helped = !1;
13581359
},
13591360
SetHelped: function() {
@@ -1394,8 +1395,7 @@
13941395
});
13951396
return query;
13961397
}
1397-
});
1398-
AbstractSQLOptimiser.initialize = function() {
1398+
})).initialize = function() {
13991399
this.helped = !1;
14001400
};
14011401
});

test/sbvr/test.coffee

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ module.exports = exports = (builtInVocab = false) ->
2929
expectation(result)
3030

3131
runMigration = (describe, src, dst, expectation) ->
32-
it 'Migration: \n\nVocabulary: src\n' + src + '\n\nVocabulary: dst\n' + dst, ->
32+
describe 'Migration', ->
33+
it 'Vocabulary: src\n' + src + '\n\nVocabulary: dst\n' + dst, ->
3334
SBVRParser.reset()
3435
srcLf = SBVRParser.matchAll(src, 'Process')
3536
srcSchema = LF2AbstractSQLTranslator(srcLf, 'Process')
@@ -39,7 +40,7 @@ module.exports = exports = (builtInVocab = false) ->
3940
dstSchema = LF2AbstractSQLTranslator(dstLf, 'Process')
4041

4142
migration = AbstractSQLCompiler.postgres.diffSchemas(srcSchema, dstSchema)
42-
43+
4344
expect(migration).to.deep.equal(expectation)
4445

4546
runSchema = (describe, input, expectation) ->

0 commit comments

Comments
 (0)