Merge pull request #3323 from Human-Connection/3322-fix-image-url-returns-undefined

fix(migration): return null for Image.url
This commit is contained in:
Robert Schäfer 2020-03-24 13:41:23 +01:00 committed by GitHub
commit 0f471235e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 105 additions and 6 deletions

View File

@ -23,7 +23,7 @@ export async function up() {
[
`
MATCH (post:Post)
WHERE post.image IS NOT NULL
WHERE post.image IS NOT NULL AND post.deleted = FALSE
MERGE(image:Image {url: post.image})
CREATE (post)-[:HERO_IMAGE]->(image)
SET
@ -36,14 +36,14 @@ export async function up() {
`,
`
MATCH (user:User)
WHERE user.avatar IS NOT NULL
WHERE user.avatar IS NOT NULL AND user.deleted = FALSE
MERGE(avatar:Image {url: user.avatar})
CREATE (user)-[:AVATAR_IMAGE]->(avatar)
REMOVE user.avatar
`,
`
MATCH (user:User)
WHERE user.coverImg IS NOT NULL
WHERE user.coverImg IS NOT NULL AND user.deleted = FALSE
MERGE(coverImage:Image {url: user.coverImg})
CREATE (user)-[:COVER_IMAGE]->(coverImage)
REMOVE user.coverImg

View File

@ -0,0 +1,44 @@
import { getDriver } from '../../db/neo4j'
export const description =
'We should not maintain obsolete attributes for users who have been deleted.'
export async function up(next) {
const driver = getDriver()
const session = driver.session()
const transaction = session.beginTransaction()
const updateDeletedUserAttributes = await transaction.run(`
MATCH (user:User)
WHERE user.deleted = TRUE
SET user.createdAt = 'UNAVAILABLE'
SET user.updatedAt = 'UNAVAILABLE'
SET user.lastActiveAt = 'UNAVAILABLE'
SET user.termsAndConditionsAgreedVersion = 'UNAVAILABLE'
SET user.avatar = null
SET user.coverImg = null
RETURN user {.*};
`)
try {
// Implement your migration here.
const users = await updateDeletedUserAttributes.records.map(record => record.get('user'))
// eslint-disable-next-line no-console
console.log(users)
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()
}
}
export async function down(next) {
// eslint-disable-next-line no-console
console.log('Irreversible migration')
next()
}

View File

@ -0,0 +1,46 @@
import { getDriver } from '../../db/neo4j'
export const description =
'We should not maintain obsolete attributes for posts which have been deleted.'
export async function up(next) {
const driver = getDriver()
const session = driver.session()
const transaction = session.beginTransaction()
const updateDeletedPostsAttributes = await transaction.run(`
MATCH (post:Post)
WHERE post.deleted = TRUE
SET post.language = 'UNAVAILABLE'
SET post.createdAt = 'UNAVAILABLE'
SET post.updatedAt = 'UNAVAILABLE'
SET post.content = 'UNAVAILABLE'
SET post.title = 'UNAVAILABLE'
SET post.visibility = 'UNAVAILABLE'
SET post.contentExcerpt = 'UNAVAILABLE'
SET post.image = null
RETURN post {.*};
`)
try {
// Implement your migration here.
const posts = await updateDeletedPostsAttributes.records.map(record => record.get('post'))
// eslint-disable-next-line no-console
console.log(posts)
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()
}
}
export async function down(next) {
// eslint-disable-next-line no-console
console.log('Irreversible migration')
next()
}

View File

@ -17,10 +17,10 @@ const obfuscate = async (resolve, root, args, context, info) => {
root.contentExcerpt = 'UNAVAILABLE'
root.title = 'UNAVAILABLE'
root.slug = 'UNAVAILABLE'
root.avatar = 'UNAVAILABLE'
root.avatar = null
root.about = 'UNAVAILABLE'
root.name = 'UNAVAILABLE'
root.image = null // avoid unecessary 500 errors
root.image = null
}
return resolve(root, args, context, info)
}

View File

@ -192,6 +192,9 @@ export default {
SET resource.deleted = true
SET resource.content = 'UNAVAILABLE'
SET resource.contentExcerpt = 'UNAVAILABLE'
SET resource.language = 'UNAVAILABLE'
SET resource.createdAt = 'UNAVAILABLE'
SET resource.updatedAt = 'UNAVAILABLE'
SET comment.deleted = true
RETURN resource {.*}
`,
@ -214,6 +217,11 @@ export default {
SET user.deleted = true
SET user.name = 'UNAVAILABLE'
SET user.about = 'UNAVAILABLE'
SET user.lastActiveAt = 'UNAVAILABLE'
SET user.createdAt = 'UNAVAILABLE'
SET user.updatedAt = 'UNAVAILABLE'
SET user.termsAndConditionsAgreedVersion = 'UNAVAILABLE'
SET user.encryptedPassword = null
WITH user
OPTIONAL MATCH (user)<-[:BELONGS_TO]-(email:EmailAddress)
DETACH DELETE email

View File

@ -201,7 +201,6 @@ type Query {
title: String
slug: String
content: String
image: String
visibility: Visibility
pinned: Boolean
createdAt: String

View File

@ -23,6 +23,7 @@ export default () => {
contentExcerpt
language
image {
url
sensitive
}
}
@ -52,6 +53,7 @@ export default () => {
contentExcerpt
language
image {
url
sensitive
aspectRatio
}