From 60a0ea582ea659a4ba0d8ead8342b4e92802de89 Mon Sep 17 00:00:00 2001 From: Daniel Hutzel Date: Fri, 30 Jun 2023 18:37:15 +0200 Subject: [PATCH] Using UPSERTs in init.js --- bookshop/db/init.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/bookshop/db/init.js b/bookshop/db/init.js index bfa0fc89..6e2084f7 100644 --- a/bookshop/db/init.js +++ b/bookshop/db/init.js @@ -4,15 +4,8 @@ * currencies, if not obtained through @capire/common. */ -module.exports = async (tx)=>{ - - const has_common = tx.model.definitions['sap.common.Currencies']?.elements.numcode - if (has_common) return - - const already_filled = await tx.exists('sap.common.Currencies',{code:'EUR'}) - if (already_filled) return - - await tx.run (INSERT.into ('sap.common.Currencies') .columns ( +module.exports = async ()=>{ + await UPSERT.into ('sap.common.Currencies') .columns ( [ 'code', 'symbol', 'name' ] ) .rows ( [ 'EUR', '€', 'Euro' ], @@ -20,5 +13,5 @@ module.exports = async (tx)=>{ [ 'GBP', '£', 'British Pound' ], [ 'ILS', '₪', 'Shekel' ], [ 'JPY', '¥', 'Yen' ], - )) + ) }