mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
* type for neo4j and neode * fix build * remove flakyness * wait for neode to install schema * remove flakyness * explain why we wait for a non-promise
69 lines
2.0 KiB
TypeScript
69 lines
2.0 KiB
TypeScript
/* eslint-disable @typescript-eslint/require-await */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
import { getDriver } from '@db/neo4j'
|
|
|
|
export const description = `
|
|
All users commenting a post observe the post.
|
|
`
|
|
|
|
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 (commenter:User)-[:WROTE]->(:Comment)-[:COMMENTS]->(post:Post)
|
|
MERGE (commenter)-[obs:OBSERVES]->(post)
|
|
ON CREATE SET
|
|
obs.active = true,
|
|
obs.createdAt = toString(datetime()),
|
|
obs.updatedAt = toString(datetime())
|
|
RETURN post
|
|
`)
|
|
await transaction.commit()
|
|
} 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 {
|
|
await 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 (u:User)-[obs:OBSERVES]->(p:Post)<-[:COMMENTS]-(:Comment)<-[:WROTE]-(u)
|
|
WHERE NOT (u)-[:WROTE]->(post)
|
|
DELETE obs
|
|
RETURN p
|
|
`)
|
|
await transaction.commit()
|
|
} 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 {
|
|
await session.close()
|
|
}
|
|
}
|