mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2026-01-18 02:41:23 +00:00
migration added to swap lat and lng in db
This commit is contained in:
parent
cb8b2acffd
commit
4905b09b3e
@ -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()
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user