Merge pull request #2589 from Human-Connection/2587-geolocation-swap-lng-with-lat

fix: swap lat and lng
This commit is contained in:
Robert Schäfer 2020-02-18 17:55:57 +01:00 committed by GitHub
commit b003fb3f10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 14 deletions

View File

@ -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()
}

View File

@ -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)
}

View File

@ -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',

View File

@ -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',
})

View File

@ -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 =

View File

@ -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',