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 new file mode 100644 index 000000000..619e30320 --- /dev/null +++ b/backend/src/db/migrations/20200206190233-swap_latitude_with_longitude.js @@ -0,0 +1,42 @@ +import { getDriver } from '../../db/neo4j' + +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() + 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') + throw new Error(error) + } finally { + session.close() + } +} + +export async function up(next) { + swap(next) +} + +export async function down(next) { + swap(next) +} diff --git a/backend/src/db/seed.js b/backend/src/db/seed.js index cf36f3039..d1e430629 100644 --- a/backend/src/db/seed.js +++ b/backend/src/db/seed.js @@ -31,8 +31,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', @@ -47,8 +47,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', @@ -77,8 +77,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', diff --git a/backend/src/schema/resolvers/locations.spec.js b/backend/src/schema/resolvers/locations.spec.js index a2929f65a..34d0f2e9d 100644 --- a/backend/src/schema/resolvers/locations.spec.js +++ b/backend/src/schema/resolvers/locations.spec.js @@ -51,8 +51,8 @@ describe('resolvers', () => { id: 'region.9397217726497330', name: 'Paris', type: 'region', - lat: 2.35183, - lng: 48.85658, + lng: 2.35183, + lat: 48.85658, nameEN: 'Paris', }) 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 = diff --git a/backend/src/schema/resolvers/users/location.spec.js b/backend/src/schema/resolvers/users/location.spec.js index 5b9a49a6a..04216dcb5 100644 --- a/backend/src/schema/resolvers/users/location.spec.js +++ b/backend/src/schema/resolvers/users/location.spec.js @@ -41,7 +41,7 @@ const updateUserMutation = gql` let newlyCreatedNodesWithLocales = [ { city: { - lng: 41.1534, + lat: 41.1534, nameES: 'Hamburg', nameFR: 'Hamburg', nameIT: 'Hamburg', @@ -54,7 +54,7 @@ let newlyCreatedNodesWithLocales = [ name: 'Hamburg', namePL: 'Hamburg', id: 'place.5977106083398860', - lat: -74.5763, + lng: -74.5763, }, state: { namePT: 'Nova Jérsia', @@ -150,7 +150,7 @@ describe('userMiddleware', () => { newlyCreatedNodesWithLocales = [ { city: { - lng: 53.55, + lat: 53.55, nameES: 'Hamburgo', nameFR: 'Hambourg', nameIT: 'Amburgo', @@ -163,7 +163,7 @@ describe('userMiddleware', () => { namePL: 'Hamburg', name: 'Hamburg', id: 'region.10793468240398860', - lat: 10, + lng: 10, }, country: { namePT: 'Alemanha',