mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
migration for clickedCount
This commit is contained in:
parent
4862d53196
commit
4611e298f5
@ -0,0 +1,53 @@
|
|||||||
|
import { getDriver } from '../../db/neo4j'
|
||||||
|
|
||||||
|
export const description = `
|
||||||
|
This migration adds the clickedCount property to all posts, setting it to 0.
|
||||||
|
`
|
||||||
|
|
||||||
|
module.exports.up = async function (next) {
|
||||||
|
const driver = getDriver()
|
||||||
|
const session = driver.session()
|
||||||
|
const transaction = session.beginTransaction()
|
||||||
|
try {
|
||||||
|
// Implement your migration here.
|
||||||
|
await transaction.run(`
|
||||||
|
MATCH (p:Post)
|
||||||
|
SET p.clickedCount = 0
|
||||||
|
`)
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.down = async function (next) {
|
||||||
|
const driver = getDriver()
|
||||||
|
const session = driver.session()
|
||||||
|
const transaction = session.beginTransaction()
|
||||||
|
try {
|
||||||
|
// Implement your migration here.
|
||||||
|
await transaction.run(`
|
||||||
|
MATCH (p:Post)
|
||||||
|
REMOVE p.clickedCount
|
||||||
|
`)
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user