mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
fix(migration): return null for Image.url
This commit is contained in:
parent
7371c34fec
commit
e0e026a8b8
@ -23,7 +23,7 @@ export async function up() {
|
|||||||
[
|
[
|
||||||
`
|
`
|
||||||
MATCH (post:Post)
|
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})
|
MERGE(image:Image {url: post.image})
|
||||||
CREATE (post)-[:HERO_IMAGE]->(image)
|
CREATE (post)-[:HERO_IMAGE]->(image)
|
||||||
SET
|
SET
|
||||||
@ -36,14 +36,14 @@ export async function up() {
|
|||||||
`,
|
`,
|
||||||
`
|
`
|
||||||
MATCH (user:User)
|
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})
|
MERGE(avatar:Image {url: user.avatar})
|
||||||
CREATE (user)-[:AVATAR_IMAGE]->(avatar)
|
CREATE (user)-[:AVATAR_IMAGE]->(avatar)
|
||||||
REMOVE user.avatar
|
REMOVE user.avatar
|
||||||
`,
|
`,
|
||||||
`
|
`
|
||||||
MATCH (user:User)
|
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})
|
MERGE(coverImage:Image {url: user.coverImg})
|
||||||
CREATE (user)-[:COVER_IMAGE]->(coverImage)
|
CREATE (user)-[:COVER_IMAGE]->(coverImage)
|
||||||
REMOVE user.coverImg
|
REMOVE user.coverImg
|
||||||
|
|||||||
@ -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()
|
||||||
|
}
|
||||||
@ -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()
|
||||||
|
}
|
||||||
@ -2,7 +2,7 @@ import Resolver from './helpers/Resolver'
|
|||||||
export default {
|
export default {
|
||||||
Image: {
|
Image: {
|
||||||
...Resolver('Image', {
|
...Resolver('Image', {
|
||||||
undefinedToNull: ['sensitive', 'alt', 'aspectRatio'],
|
undefinedToNull: ['sensitive', 'alt', 'aspectRatio', 'url'],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -192,6 +192,9 @@ export default {
|
|||||||
SET resource.deleted = true
|
SET resource.deleted = true
|
||||||
SET resource.content = 'UNAVAILABLE'
|
SET resource.content = 'UNAVAILABLE'
|
||||||
SET resource.contentExcerpt = 'UNAVAILABLE'
|
SET resource.contentExcerpt = 'UNAVAILABLE'
|
||||||
|
SET resource.language = 'UNAVAILABLE'
|
||||||
|
SET resource.createdAt = 'UNAVAILABLE'
|
||||||
|
SET resource.updatedAt = 'UNAVAILABLE'
|
||||||
SET comment.deleted = true
|
SET comment.deleted = true
|
||||||
RETURN resource {.*}
|
RETURN resource {.*}
|
||||||
`,
|
`,
|
||||||
@ -214,6 +217,11 @@ export default {
|
|||||||
SET user.deleted = true
|
SET user.deleted = true
|
||||||
SET user.name = 'UNAVAILABLE'
|
SET user.name = 'UNAVAILABLE'
|
||||||
SET user.about = '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
|
WITH user
|
||||||
OPTIONAL MATCH (user)<-[:BELONGS_TO]-(email:EmailAddress)
|
OPTIONAL MATCH (user)<-[:BELONGS_TO]-(email:EmailAddress)
|
||||||
DETACH DELETE email
|
DETACH DELETE email
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
type Image {
|
type Image {
|
||||||
url: ID!,
|
url: ID,
|
||||||
# urlW34: String,
|
# urlW34: String,
|
||||||
# urlW160: String,
|
# urlW160: String,
|
||||||
# urlW320: String,
|
# urlW320: String,
|
||||||
|
|||||||
@ -23,6 +23,7 @@ export default () => {
|
|||||||
contentExcerpt
|
contentExcerpt
|
||||||
language
|
language
|
||||||
image {
|
image {
|
||||||
|
url
|
||||||
sensitive
|
sensitive
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,6 +53,7 @@ export default () => {
|
|||||||
contentExcerpt
|
contentExcerpt
|
||||||
language
|
language
|
||||||
image {
|
image {
|
||||||
|
url
|
||||||
sensitive
|
sensitive
|
||||||
aspectRatio
|
aspectRatio
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user