fix: upsert logic

This commit is contained in:
NunoSempere 2022-02-12 16:24:16 -05:00
parent 8b6f648c08
commit 3a901077c9

View File

@ -195,15 +195,14 @@ pgInsert({
*/ */
export async function pgUpsert({ contents, schema, tableName }) { export async function pgUpsert({ contents, schema, tableName }) {
if (tableWhiteList.includes(`${schema}.${tableName}`)) { if (tableWhiteList.includes(`${schema}.${tableName}`)) {
if (schema == "latest") { if (schema == "latest") {
await dropTable(schema, tableName); await runPgCommand({ command: dropTable(schema, tableName), pool: readWritePool })
await buildMetaforecastTable(schema, tableName); await runPgCommand({ command: buildMetaforecastTable(schema, tableName), pool: readWritePool })
await createUniqueIndex(schema, tableName) await runPgCommand({ command: createUniqueIndex(schema, tableName), pool: readWritePool })
} }
console.log(`Inserting into postgres table ${schema}.${tableName}`) console.log(`Upserting into postgres table ${schema}.${tableName}`)
console.log({ contents, schema, tableName })
let i = 0 let i = 0
for (let datum of contents) { for (let datum of contents) {
await pgInsert({ datum, schema, tableName }) await pgInsert({ datum, schema, tableName })