Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Commit

Permalink
fix: handle more complex cascading views correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Zaschka committed Jun 24, 2021
1 parent 66ddc08 commit 7bee324
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
32 changes: 16 additions & 16 deletions src/ChangeLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export class ChangeLog {
const aViewName = a.changeSet.changes[0].dropView.viewName
const bViewName = b.changeSet.changes[0].dropView.viewName

const aRegex = RegExp(`FROM ${aViewName}|JOIN ${aViewName}`, 'gm')
const bRegex = RegExp(`FROM ${bViewName}|JOIN ${bViewName}`, 'gm')
const aRegex = RegExp(`FROM \\(?${aViewName}|JOIN \\(?${aViewName}`, 'gm')
const bRegex = RegExp(`FROM \\(?${bViewName}|JOIN \\(?${bViewName}`, 'gm')

// Does b directly depend on a
if (bRegex.test(viewDefinitions[aViewName].definition)) {
Expand Down Expand Up @@ -181,8 +181,8 @@ export class ChangeLog {
const aViewName = a.changeSet.changes[0].createView.viewName
const bViewName = b.changeSet.changes[0].createView.viewName

const aRegex = RegExp(`FROM ${aViewName}|JOIN ${aViewName}`, 'gm')
const bRegex = RegExp(`FROM ${bViewName}|JOIN ${bViewName}`, 'gm')
const aRegex = RegExp(`FROM \\(?${aViewName}|JOIN \\(?${aViewName}`, 'gm')
const bRegex = RegExp(`FROM \\(?${bViewName}|JOIN \\(?${bViewName}`, 'gm')

if (bRegex.test(a.changeSet.changes[0].createView.selectQuery)) {
return 1
Expand All @@ -192,18 +192,18 @@ export class ChangeLog {
}

// Does a depend on any other view
for (const key in viewDefinitions) {
if (aRegex.test(viewDefinitions[key].definition)) {
return -1
}
}

// Does b depend on any other view
for (const key in viewDefinitions) {
if (bRegex.test(viewDefinitions[key].definition)) {
return 1
}
}
// for (const key in viewDefinitions) {
// if (aRegex.test(viewDefinitions[key].definition)) {
// return -1
// }
// }
//
// // Does b depend on any other view
// for (const key in viewDefinitions) {
// if (bRegex.test(viewDefinitions[key].definition)) {
// return 1
// }
// }

// Nothing? Then order by name
return aViewName > bViewName ? -1 : 1
Expand Down
8 changes: 5 additions & 3 deletions src/DataLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class DataLoader {
if (folders.size === 0) return
for (let folder of folders) {
const files = await readdir(folder)
for (let each of files.filter(this._filterCsvFiles)) {
for (let each of files.filter(this._filterCsvFiles.bind(this))) {
// Verify entity
let name = each.replace(/-/g, '.').slice(0, -path.extname(each).length)
let entity = this._entity4(name)
Expand Down Expand Up @@ -103,14 +103,16 @@ export class DataLoader {
for (const row of rows) {
const keyColumns = Object.keys(entity.keys)
let where = keyColumns.reduce((set, col, index) => {
set[col] = row[index]
set[col] = row[cols.indexOf(col)];
return set
}, {})

let record = await SELECT.from(entity.name).columns(keyColumns.join(',')).where(where)
if (record.length > 0) {
let set = cols.reduce((set, col, index) => {
set[col] = row[index]
if(typeof row[index] !== "undefined") {
set[col] = row[index];
}
return set
}, {})
await UPDATE(entity.name).set(set).where(where)
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const sortByCasadingViews = (a: any, b: any) => {
}
}

return -1
return 0
}

export { sortByCasadingViews }

0 comments on commit 7bee324

Please sign in to comment.