Skip to content

Commit b2d522d

Browse files
Update seeding logic
Seeding logic updated to handle updating specific column names
1 parent 4269e50 commit b2d522d

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/spec.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,21 +607,44 @@ class Spec {
607607
})
608608
}
609609

610-
async _upsertAndSeedLiveColumns() {
610+
async _upsertAndSeedLiveColumns(columns?: { path: string }[]) {
611+
if (columns) {
612+
this.hasCalledUpsertAndSeedLiveColumns = false
613+
}
611614
let liveColumnsToSeed = []
612615

613616
// Detect any changes with live columns or links (filterBy, uniqueBy, etc.).
617+
const isAllColumns =
618+
columns && columns.length === 1 && columns[0].path.split('.')[2] === '*'
619+
620+
// Upsert any new/changed live columns listed in the config.
621+
// We will seed (or re-seed) all live columns that were upserted.
614622
const upsertLiveColumnService = new UpsertLiveColumnsService()
615623
try {
616624
await upsertLiveColumnService.perform()
617625
liveColumnsToSeed = upsertLiveColumnService.liveColumnsToUpsert
626+
627+
if (columns) {
628+
liveColumnsToSeed.push(
629+
...upsertLiveColumnService.prevLiveColumns.filter((c) => {
630+
const result = isAllColumns
631+
? true
632+
: columns.some((col) => {
633+
return col.path === c.columnPath
634+
})
635+
return result
636+
})
637+
)
638+
// remove duplicates from liveColumnsToSeed
639+
liveColumnsToSeed = liveColumnsToSeed.filter((v, i, a) => a.indexOf(v) === i)
640+
}
618641
} catch (err) {
619642
logger.error(`Failed to upsert live columns: ${err}`)
620643
liveColumnsToSeed = []
621644
}
622645

623-
const tablePathsUsingLiveObjectId = upsertLiveColumnService.tablePathsUsingLiveObjectId
624-
const newLiveTablePaths = upsertLiveColumnService.newLiveTablePaths
646+
const tablePathsUsingLiveObjectId: { [key: string]: Set<string> } = {}
647+
const newLiveTablePaths = new Set<string>()
625648

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

0 commit comments

Comments
 (0)