Skip to content

Commit

Permalink
[BUGFIX] do not upload hubdb without confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
dmh committed Feb 16, 2024
1 parent 31fcc1e commit a092a3b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
40 changes: 21 additions & 19 deletions lib/hubspot/hubdb/hubdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,28 @@ async function uploadHubDb (config) {
const table = tables.results.find((/** @type {any} */ t) => t.name === file.label)
if (table) {
console.warn(`${chalk.red('[Warning]')} ${chalk.magenta(file.label)} table already exists in the selected account.`)
await confirmTableOverwrite(file.label)
const spinner = ora(overwriteMsg(file.label)).start()
try {
// get table rows from the json file
const rows = require(file.path).rows
// update table columns and options
await updateHubDbTable(accountId, table.id, file.path)
// check if remote table has rows
const remoteRows = await fetchRows(accountId, table.id)
if (remoteRows.results.length) {
// clear remote table rows if exists
await clearHubDbTableRows(accountId, table.id)
const confirm = await confirmTableOverwrite(file.label)
if (confirm) {
const spinner = ora(overwriteMsg(file.label)).start()
try {
// get table rows from the json file
const rows = require(file.path).rows
// update table columns and options
await updateHubDbTable(accountId, table.id, file.path)
// check if remote table has rows
const remoteRows = await fetchRows(accountId, table.id)
if (remoteRows.results.length) {
// clear remote table rows if exists
await clearHubDbTableRows(accountId, table.id)
}
// add new rows to the table from the json file
await addRowsToHubDbTable(accountId, table.id, rows)
spinner.succeed()
} catch (error) {
spinner.fail()
console.error(error)
process.exit(1)
}
// add new rows to the table from the json file
await addRowsToHubDbTable(accountId, table.id, rows)
spinner.succeed()
} catch (error) {
spinner.fail()
console.error(error)
process.exit(1)
}
} else {
// create and publish table if it does not exist
Expand Down
3 changes: 0 additions & 3 deletions lib/hubspot/hubdb/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ async function confirmTableOverwrite (tableName) {
}
}
const confirmed = await confirm(confirmOverwrite(tableName))
if (!confirmed) {
process.exit(0)
}
return confirmed
}

Expand Down

0 comments on commit a092a3b

Please sign in to comment.