Merge pull request #2919 from Human-Connection/2894-add-migration-for-muted-relationship

fix(backend): Add migration for muted relationship
This commit is contained in:
Robert Schäfer 2020-01-28 22:24:14 +01:00 committed by GitHub
commit d98b30fce1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 9 deletions

View File

@ -2,30 +2,44 @@ import { getDriver } from '../../db/neo4j'
export const description = ''
export function up(next) {
export async function up(next) {
const driver = getDriver()
const session = driver.session()
const transaction = session.beginTransaction()
try {
// Implement your migration here.
await transaction.run(``)
await transaction.commit()
next()
} catch (err) {
next(err)
} 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()
driver.close()
}
}
export function down(next) {
export async function down(next) {
const driver = getDriver()
const session = driver.session()
const transaction = session.beginTransaction()
try {
// Rollback your migration here.
// Implement your migration here.
await transaction.run(``)
await transaction.commit()
next()
} catch (err) {
next(err)
} 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()
driver.close()
}
}

View File

@ -0,0 +1,46 @@
import { getDriver } from '../../db/neo4j'
export const description = `
This migration creates a MUTED relationship between two edges(:User) that have a pre-existing BLOCKED relationship.
It also sets the createdAt date for the BLOCKED relationship to the datetime the migration was run. This became
necessary after we redefined what it means to block someone, and what it means to mute them. Muting is about filtering
another user's content, whereas blocking means preventing that user from interacting with you/your contributions.
A blocked user will still be able to see your contributions, but will not be able to interact with them and vice versa.
`
export async function up(next) {
const driver = getDriver()
const session = driver.session()
const transaction = session.beginTransaction()
try {
await transaction.run(
`
MATCH (blocker:User)-[blocked:BLOCKED]->(blockee:User)
MERGE (blocker)-[muted:MUTED]->(blockee)
SET muted.createdAt = toString(datetime()), blocked.createdAt = toString(datetime())
`,
)
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')
} finally {
session.close()
}
}
export function down(next) {
const driver = getDriver()
const session = driver.session()
try {
// Rollback your migration here.
next()
} catch (err) {
next(err)
} finally {
session.close()
}
}

View File

@ -77,12 +77,18 @@ export default {
relationship: 'BLOCKED',
target: 'User',
direction: 'out',
properties: {
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
},
},
muted: {
type: 'relationship',
relationship: 'MUTED',
target: 'User',
direction: 'out',
properties: {
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
},
},
notifications: {
type: 'relationship',