From 31cec2cf0c295352d4e032a24ed7ac219a912c8e Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 11 Feb 2020 14:37:10 +0100 Subject: [PATCH] improved migration --- ...0206190233-swap_latitude_with_longitude.js | 32 ++++--------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/backend/src/db/migrations/20200206190233-swap_latitude_with_longitude.js b/backend/src/db/migrations/20200206190233-swap_latitude_with_longitude.js index 0e11c8007..381d6db1d 100644 --- a/backend/src/db/migrations/20200206190233-swap_latitude_with_longitude.js +++ b/backend/src/db/migrations/20200206190233-swap_latitude_with_longitude.js @@ -3,11 +3,10 @@ import { getDriver } from '../../db/neo4j' export const description = 'This migration swaps the value stored in Location.lat with the value of Location.lng.' -export async function up(next) { +const swap = async function(next) { const driver = getDriver() const session = driver.session() const transaction = session.beginTransaction() - try { // Implement your migration here. await transaction.run(` @@ -23,33 +22,16 @@ export async function up(next) { await transaction.rollback() // eslint-disable-next-line no-console console.log('rolled back') + throw new Error(error) } finally { session.close() } } +export async function up(next) { + swap(next) +} + export async function down(next) { - const driver = getDriver() - const session = driver.session() - const transaction = session.beginTransaction() - - try { - // Implement your migration here. - await transaction.run( - ` - MATCH (l:Location) WHERE NOT(l.lat IS NULL) - WITH l.lng AS longitude, l.lat AS latitude, l AS Location - SET Location.lat = longitude, Location.lng = latitude `, - ) - await transaction.commit() - next() - } catch (error) { - // eslint-disable-next-line no-console - console.log(error) - await transaction.rollback() - // eslint-disable-next-line no-console - console.log('rolled back') - } finally { - session.close() - } + swap(next) }