Skip to content

Commit

Permalink
Update seeding logic
Browse files Browse the repository at this point in the history
Seeding logic updated to handle updating specific column names
  • Loading branch information
murtaza-spec-dev committed Oct 10, 2023
1 parent 4269e50 commit b2d522d
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,21 +607,44 @@ class Spec {
})
}

async _upsertAndSeedLiveColumns() {
async _upsertAndSeedLiveColumns(columns?: { path: string }[]) {
if (columns) {
this.hasCalledUpsertAndSeedLiveColumns = false
}
let liveColumnsToSeed = []

// Detect any changes with live columns or links (filterBy, uniqueBy, etc.).
const isAllColumns =
columns && columns.length === 1 && columns[0].path.split('.')[2] === '*'

// Upsert any new/changed live columns listed in the config.
// We will seed (or re-seed) all live columns that were upserted.
const upsertLiveColumnService = new UpsertLiveColumnsService()
try {
await upsertLiveColumnService.perform()
liveColumnsToSeed = upsertLiveColumnService.liveColumnsToUpsert

if (columns) {
liveColumnsToSeed.push(
...upsertLiveColumnService.prevLiveColumns.filter((c) => {
const result = isAllColumns
? true
: columns.some((col) => {
return col.path === c.columnPath
})
return result
})
)
// remove duplicates from liveColumnsToSeed
liveColumnsToSeed = liveColumnsToSeed.filter((v, i, a) => a.indexOf(v) === i)
}
} catch (err) {
logger.error(`Failed to upsert live columns: ${err}`)
liveColumnsToSeed = []
}

const tablePathsUsingLiveObjectId = upsertLiveColumnService.tablePathsUsingLiveObjectId
const newLiveTablePaths = upsertLiveColumnService.newLiveTablePaths
const tablePathsUsingLiveObjectId: { [key: string]: Set<string> } = {}
const newLiveTablePaths = new Set<string>()

// Get a map of unique live-object/table relations (grouping the column names).
const uniqueLiveObjectTablePaths = {}
Expand Down

0 comments on commit b2d522d

Please sign in to comment.