From ef9d351fcfb6e79f53e18fce4bcd2fca0adcc117 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Fri, 20 Dec 2019 01:54:04 +0100 Subject: [PATCH 1/8] swap lat and lng --- backend/src/schema/resolvers/users/location.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/schema/resolvers/users/location.js b/backend/src/schema/resolvers/users/location.js index 3f3638bf5..cc00d9e0a 100644 --- a/backend/src/schema/resolvers/users/location.js +++ b/backend/src/schema/resolvers/users/location.js @@ -34,8 +34,8 @@ const createLocation = async (session, mapboxData) => { namePL: mapboxData.text_pl, nameRU: mapboxData.text_ru, type: mapboxData.id.split('.')[0].toLowerCase(), - lat: mapboxData.center && mapboxData.center.length ? mapboxData.center[0] : null, - lng: mapboxData.center && mapboxData.center.length ? mapboxData.center[1] : null, + lng: mapboxData.center && mapboxData.center.length ? mapboxData.center[0] : null, + lat: mapboxData.center && mapboxData.center.length ? mapboxData.center[1] : null, } let mutation = From 976583b23589bcec7896cd7c01af3e17e650fc23 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Fri, 20 Dec 2019 02:54:35 +0100 Subject: [PATCH 2/8] fixing test for geolocation --- backend/src/schema/resolvers/users/location.spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/schema/resolvers/users/location.spec.js b/backend/src/schema/resolvers/users/location.spec.js index f7315174c..af13dba5b 100644 --- a/backend/src/schema/resolvers/users/location.spec.js +++ b/backend/src/schema/resolvers/users/location.spec.js @@ -42,7 +42,7 @@ const updateUserMutation = gql` let newlyCreatedNodesWithLocales = [ { city: { - lng: 41.1534, + lat: 41.1534, nameES: 'Hamburg', nameFR: 'Hamburg', nameIT: 'Hamburg', @@ -55,7 +55,7 @@ let newlyCreatedNodesWithLocales = [ name: 'Hamburg', namePL: 'Hamburg', id: 'place.5977106083398860', - lat: -74.5763, + lng: -74.5763, }, state: { namePT: 'Nova Jérsia', @@ -151,7 +151,7 @@ describe('userMiddleware', () => { newlyCreatedNodesWithLocales = [ { city: { - lng: 53.55, + lat: 53.55, nameES: 'Hamburgo', nameFR: 'Hambourg', nameIT: 'Amburgo', @@ -164,7 +164,7 @@ describe('userMiddleware', () => { namePL: 'Hamburg', name: 'Hamburg', id: 'region.10793468240398860', - lat: 10, + lng: 10, }, country: { namePT: 'Alemanha', From cb8b2acffd8d4e026151321e40fc503f3103e539 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 8 Jan 2020 02:44:47 +0100 Subject: [PATCH 3/8] swap lng and lat in db seed --- backend/src/db/seed.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/src/db/seed.js b/backend/src/db/seed.js index ba7ace90b..69b1f8dfe 100644 --- a/backend/src/db/seed.js +++ b/backend/src/db/seed.js @@ -32,8 +32,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl'] id: 'region.5127278006398860', name: 'Hamburg', type: 'region', - lat: 10.0, - lng: 53.55, + lng: 10.0, + lat: 53.55, nameES: 'Hamburgo', nameFR: 'Hambourg', nameIT: 'Amburgo', @@ -48,8 +48,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl'] id: 'region.14880313158564380', type: 'region', name: 'Berlin', - lat: 13.38333, - lng: 52.51667, + lng: 13.38333, + lat: 52.51667, nameES: 'Berlín', nameFR: 'Berlin', nameIT: 'Berlino', @@ -78,8 +78,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl'] id: 'region.9397217726497330', name: 'Paris', type: 'region', - lat: 2.35183, - lng: 48.85658, + lng: 2.35183, + lat: 48.85658, nameES: 'París', nameFR: 'Paris', nameIT: 'Parigi', From 4905b09b3e722655c65051ece7ee12c3c38c1390 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 6 Feb 2020 20:47:45 +0100 Subject: [PATCH 4/8] migration added to swap lat and lng in db --- ...0206190233-swap_latitude_with_longitude.js | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 backend/src/db/migrations/20200206190233-swap_latitude_with_longitude.js diff --git a/backend/src/db/migrations/20200206190233-swap_latitude_with_longitude.js b/backend/src/db/migrations/20200206190233-swap_latitude_with_longitude.js new file mode 100644 index 000000000..35d85430e --- /dev/null +++ b/backend/src/db/migrations/20200206190233-swap_latitude_with_longitude.js @@ -0,0 +1,54 @@ +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 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() + } +} + +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() + } +} From 86f298f8e5ce588da1ac6751ed3cc15dea346fdb Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 6 Feb 2020 23:00:06 +0100 Subject: [PATCH 5/8] prettier, prettier --- .../migrations/20200206190233-swap_latitude_with_longitude.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 35d85430e..0e11c8007 100644 --- a/backend/src/db/migrations/20200206190233-swap_latitude_with_longitude.js +++ b/backend/src/db/migrations/20200206190233-swap_latitude_with_longitude.js @@ -1,6 +1,7 @@ import { getDriver } from '../../db/neo4j' -export const description = 'This migration swaps the value stored in Location.lat with the value of Location.lng.' +export const description = + 'This migration swaps the value stored in Location.lat with the value of Location.lng.' export async function up(next) { const driver = getDriver() From 1ae6769c7d65f12a2b2f9fe665f9cbe26a898200 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 11 Feb 2020 11:33:47 +0100 Subject: [PATCH 6/8] spec for location swapped lng and lat too --- backend/src/schema/resolvers/locations.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/schema/resolvers/locations.spec.js b/backend/src/schema/resolvers/locations.spec.js index aba11f9bc..728baaa87 100644 --- a/backend/src/schema/resolvers/locations.spec.js +++ b/backend/src/schema/resolvers/locations.spec.js @@ -53,8 +53,8 @@ describe('resolvers', () => { id: 'region.9397217726497330', name: 'Paris', type: 'region', - lat: 2.35183, - lng: 48.85658, + lng: 2.35183, + lat: 48.85658, nameEN: 'Paris', }) From 31cec2cf0c295352d4e032a24ed7ac219a912c8e Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 11 Feb 2020 14:37:10 +0100 Subject: [PATCH 7/8] 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) } From 5b41561cc42b118bdb8f03a505effd1f7d158162 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 18 Feb 2020 14:16:46 +0100 Subject: [PATCH 8/8] throw error added to template --- backend/src/db/migrate/template.js | 1 + .../20200206190233-swap_latitude_with_longitude.js | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/src/db/migrate/template.js b/backend/src/db/migrate/template.js index 1d63673b4..9adb0786d 100644 --- a/backend/src/db/migrate/template.js +++ b/backend/src/db/migrate/template.js @@ -18,6 +18,7 @@ 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() } 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 381d6db1d..619e30320 100644 --- a/backend/src/db/migrations/20200206190233-swap_latitude_with_longitude.js +++ b/backend/src/db/migrations/20200206190233-swap_latitude_with_longitude.js @@ -1,7 +1,12 @@ import { getDriver } from '../../db/neo4j' -export const description = - 'This migration swaps the value stored in Location.lat with the value of Location.lng.' +export const description = ` +This migration swaps the value stored in Location.lat with the value +of Location.lng. This is necessary as the values of lat and lng were +stored incorrectly. For example Hamburg, Germany, was stored with the +values lat=10.0 and lng=53.55, which is close to the horn of Africa, +but it is lat=53.55 and lng=10.0 +` const swap = async function(next) { const driver = getDriver() @@ -11,8 +16,8 @@ const swap = async function(next) { // 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 + WITH l.lng AS longitude, l.lat AS latitude, l AS location + SET location.lat = longitude, location.lng = latitude `) await transaction.commit() next()