diff --git a/backend/src/db/migrate/template.js b/backend/src/db/migrate/template.js index b8511e9bb9..1d63673b4e 100644 --- a/backend/src/db/migrate/template.js +++ b/backend/src/db/migrate/template.js @@ -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() } } diff --git a/backend/src/db/migrations/20200127110135-create_muted_relationship_between_existing_blocked_relationships.js b/backend/src/db/migrations/20200127110135-create_muted_relationship_between_existing_blocked_relationships.js new file mode 100644 index 0000000000..ce46be9d66 --- /dev/null +++ b/backend/src/db/migrations/20200127110135-create_muted_relationship_between_existing_blocked_relationships.js @@ -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() + } +} diff --git a/backend/src/models/User.js b/backend/src/models/User.js index c3ac434ec6..055cbfc83a 100644 --- a/backend/src/models/User.js +++ b/backend/src/models/User.js @@ -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',