mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Merge pull request #6306 from Ocelot-Social-Community/update-database
refactor(database): update neo4j to 4.4
This commit is contained in:
commit
57d3e114c7
@ -11,13 +11,13 @@ export async function up(next) {
|
||||
const transaction = session.beginTransaction()
|
||||
|
||||
try {
|
||||
// Implement your migration here.
|
||||
await transaction.run(`
|
||||
CREATE CONSTRAINT ON ( group:Group ) ASSERT group.id IS UNIQUE
|
||||
`)
|
||||
await transaction.run(`
|
||||
CREATE CONSTRAINT ON ( group:Group ) ASSERT group.slug IS UNIQUE
|
||||
`)
|
||||
// Those two indexes already exist
|
||||
// await transaction.run(`
|
||||
// CREATE CONSTRAINT ON ( group:Group ) ASSERT group.id IS UNIQUE
|
||||
// `)
|
||||
// await transaction.run(`
|
||||
// CREATE CONSTRAINT ON ( group:Group ) ASSERT group.slug IS UNIQUE
|
||||
// `)
|
||||
await transaction.run(`
|
||||
CALL db.index.fulltext.createNodeIndex("group_fulltext_search",["Group"],["name", "slug", "about", "description"])
|
||||
`)
|
||||
|
||||
@ -10,7 +10,7 @@ export async function up(next) {
|
||||
try {
|
||||
// Drop indexes if they exist because due to legacy code they might be set already
|
||||
const indexesResponse = await transaction.run(`CALL db.indexes()`)
|
||||
const indexes = indexesResponse.records.map((record) => record.get('indexName'))
|
||||
const indexes = indexesResponse.records.map((record) => record.get('name'))
|
||||
if (indexes.indexOf('user_fulltext_search') > -1) {
|
||||
await transaction.run(`CALL db.index.fulltext.drop("user_fulltext_search")`)
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ const queryNotificationEmails = async (context, notificationUserIds) => {
|
||||
RETURN emailAddress {.email}
|
||||
`
|
||||
const session = context.driver.session()
|
||||
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
|
||||
const writeTxResultPromise = session.readTransaction(async (transaction) => {
|
||||
const emailAddressTransactionResponse = await transaction.run(userEmailCypher, {
|
||||
notificationUserIds,
|
||||
})
|
||||
@ -238,7 +238,7 @@ const notifyUsersOfMention = async (label, id, idsOfUsers, reason, context) => {
|
||||
[(resource)<-[:WROTE]-(author:User) | author {.*}] AS authors,
|
||||
[(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post{.*, author: properties(author)} ] AS posts
|
||||
WITH resource, user, notification, authors, posts,
|
||||
resource {.*, __typename: filter(l IN labels(resource) WHERE l IN ['Post', 'Comment', 'Group'])[0], author: authors[0], post: posts[0]} AS finalResource
|
||||
resource {.*, __typename: [l IN labels(resource) WHERE l IN ['Post', 'Comment', 'Group']][0], author: authors[0], post: posts[0]} AS finalResource
|
||||
SET notification.read = FALSE
|
||||
SET notification.createdAt = COALESCE(notification.createdAt, toString(datetime()))
|
||||
SET notification.updatedAt = toString(datetime())
|
||||
|
||||
@ -64,7 +64,7 @@ const validateReview = async (resolve, root, args, context, info) => {
|
||||
WHERE resource:User OR resource:Post OR resource:Comment
|
||||
OPTIONAL MATCH (:User)-[filed:FILED]->(:Report {closed: false})-[:BELONGS_TO]->(resource)
|
||||
OPTIONAL MATCH (resource)<-[:WROTE]-(author:User)
|
||||
RETURN filter(l IN labels(resource) WHERE l IN ['Post', 'Comment', 'User'])[0] AS label, author, filed
|
||||
RETURN [l IN labels(resource) WHERE l IN ['Post', 'Comment', 'User']][0] AS label, author, filed
|
||||
`,
|
||||
{
|
||||
resourceId,
|
||||
|
||||
@ -21,7 +21,7 @@ export default {
|
||||
MATCH (post:Post {id: $postId})
|
||||
MATCH (author:User {id: $userId})
|
||||
WITH post, author
|
||||
CREATE (comment:Comment {params})
|
||||
CREATE (comment:Comment $params)
|
||||
SET comment.createdAt = toString(datetime())
|
||||
SET comment.updatedAt = toString(datetime())
|
||||
MERGE (post)<-[:COMMENTS]-(comment)<-[:WROTE]-(author)
|
||||
|
||||
@ -147,7 +147,7 @@ describe('follow', () => {
|
||||
variables,
|
||||
})
|
||||
const relation = await neode.cypher(
|
||||
'MATCH (user:User {id: {id}})-[relationship:FOLLOWS]->(followed:User) WHERE relationship.createdAt IS NOT NULL RETURN relationship',
|
||||
'MATCH (user:User {id: $id})-[relationship:FOLLOWS]->(followed:User) WHERE relationship.createdAt IS NOT NULL RETURN relationship',
|
||||
{ id: 'u1' },
|
||||
)
|
||||
const relationshipProperties = relation.records.map(
|
||||
|
||||
@ -29,7 +29,7 @@ export default {
|
||||
* It's suggested to use query builder feature (https://github.com/adam-cowley/neode/issues/67)
|
||||
* However, pure cypher query looks cleaner IMO
|
||||
*/
|
||||
await neode.cypher(
|
||||
await neode.writeCypher(
|
||||
`MATCH (user:User {id: $currentUser.id})-[relation:FOLLOWS]->(followedUser:User {id: $followedUserId})
|
||||
DELETE relation
|
||||
RETURN COUNT(relation) > 0 as isFollowed`,
|
||||
|
||||
@ -12,13 +12,13 @@ export default {
|
||||
MATCH (resource {id: $params.resourceId})<-[:BELONGS_TO]-(report:Report {closed: false})
|
||||
WHERE resource:User OR resource:Post OR resource:Comment
|
||||
MERGE (report)<-[review:REVIEWED]-(moderator)
|
||||
ON CREATE SET review.createdAt = $dateTime, review.updatedAt = review.createdAt
|
||||
ON CREATE SET review.createdAt = $dateTime, review.updatedAt = $dateTime
|
||||
ON MATCH SET review.updatedAt = $dateTime
|
||||
SET review.disable = $params.disable
|
||||
SET report.updatedAt = $dateTime, report.disable = review.disable, report.closed = $params.closed
|
||||
SET resource.disabled = report.disable
|
||||
|
||||
WITH review, report, resource {.*, __typename: filter(l IN labels(resource) WHERE l IN ['Post', 'Comment', 'User'])[0]} AS finalResource
|
||||
WITH review, report, resource {.*, __typename: [l IN labels(resource) WHERE l IN ['Post', 'Comment', 'User']][0]} AS finalResource
|
||||
RETURN review {.*, report: properties(report), resource: properties(finalResource)}
|
||||
`
|
||||
const reviewWriteTxResultPromise = session.writeTransaction(async (txc) => {
|
||||
|
||||
@ -51,10 +51,10 @@ export default {
|
||||
OPTIONAL MATCH (resource)<-[membership:MEMBER_OF]-(relatedUser)
|
||||
WITH user, notification, resource, membership, relatedUser,
|
||||
[(resource)<-[:WROTE]-(author:User) | author {.*}] AS authors,
|
||||
[(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post {.*, author: properties(author), postType: filter(l IN labels(post) WHERE NOT l = "Post")} ] AS posts
|
||||
[(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post {.*, author: properties(author), postType: [l IN labels(post) WHERE NOT l = 'Post']} ] AS posts
|
||||
WITH resource, user, notification, authors, posts, relatedUser, membership,
|
||||
resource {.*,
|
||||
__typename: filter(l IN labels(resource) WHERE l IN ['Post', 'Comment', 'Group'])[0],
|
||||
__typename: [l IN labels(resource) WHERE l IN ['Post', 'Comment', 'Group']][0],
|
||||
author: authors[0],
|
||||
post: posts[0],
|
||||
myRole: membership.role } AS finalResource
|
||||
@ -90,10 +90,10 @@ export default {
|
||||
SET notification.read = TRUE
|
||||
WITH user, notification, resource,
|
||||
[(resource)<-[:WROTE]-(author:User) | author {.*}] AS authors,
|
||||
[(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post{.*, author: properties(author), postType: filter(l IN labels(post) WHERE NOT l = "Post")} ] AS posts
|
||||
[(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post{.*, author: properties(author), postType: [l IN labels(post) WHERE NOT l = 'Post']} ] AS posts
|
||||
OPTIONAL MATCH (resource)<-[membership:MEMBER_OF]-(user)
|
||||
WITH resource, user, notification, authors, posts, membership,
|
||||
resource {.*, __typename: filter(l IN labels(resource) WHERE l IN ['Post', 'Comment', 'Group'])[0], author: authors[0], post: posts[0], myRole: membership.role } AS finalResource
|
||||
resource {.*, __typename: [l IN labels(resource) WHERE l IN ['Post', 'Comment', 'Group']][0], author: authors[0], post: posts[0], myRole: membership.role } AS finalResource
|
||||
RETURN notification {.*, from: finalResource, to: properties(user)}
|
||||
`,
|
||||
{ resourceId: args.id, id: currentUser.id },
|
||||
@ -120,10 +120,10 @@ export default {
|
||||
SET notification.read = TRUE
|
||||
WITH user, notification, resource,
|
||||
[(resource)<-[:WROTE]-(author:User) | author {.*}] AS authors,
|
||||
[(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post{.*, author: properties(author), postType: filter(l IN labels(post) WHERE NOT l = "Post")} ] AS posts
|
||||
[(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post{.*, author: properties(author), postType: [l IN labels(post) WHERE NOT l = 'Post']} ] AS posts
|
||||
OPTIONAL MATCH (resource)<-[membership:MEMBER_OF]-(user)
|
||||
WITH resource, user, notification, authors, posts, membership,
|
||||
resource {.*, __typename: filter(l IN labels(resource) WHERE l IN ['Post', 'Comment', 'Group'])[0], author: authors[0], post: posts[0], myRole: membership.role} AS finalResource
|
||||
resource {.*, __typename: [l IN labels(resource) WHERE l IN ['Post', 'Comment', 'Group']][0], author: authors[0], post: posts[0], myRole: membership.role} AS finalResource
|
||||
RETURN notification {.*, from: finalResource, to: properties(user)}
|
||||
`,
|
||||
{ id: currentUser.id },
|
||||
|
||||
@ -146,7 +146,7 @@ export default {
|
||||
MERGE (post)<-[:WROTE]-(author)
|
||||
${categoriesCypher}
|
||||
${groupCypher}
|
||||
RETURN post {.*, postType: filter(l IN labels(post) WHERE NOT l = "Post") }
|
||||
RETURN post {.*, postType: [l IN labels(post) WHERE NOT l = 'Post'] }
|
||||
`,
|
||||
{ userId: context.user.id, categoryIds, groupId, params },
|
||||
)
|
||||
@ -214,7 +214,7 @@ export default {
|
||||
`
|
||||
}
|
||||
|
||||
updatePostCypher += `RETURN post {.*, postType: filter(l IN labels(post) WHERE NOT l = "Post")}`
|
||||
updatePostCypher += `RETURN post {.*, postType: [l IN labels(post) WHERE NOT l = 'Post']}`
|
||||
const updatePostVariables = { categoryIds, params }
|
||||
try {
|
||||
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
|
||||
|
||||
@ -251,7 +251,7 @@ describe('SignupVerification', () => {
|
||||
|
||||
it('connects User with EmailAddress', async () => {
|
||||
const cypher = `
|
||||
MATCH(email:EmailAddress)-[:BELONGS_TO]->(u:User {name: {name}})
|
||||
MATCH(email:EmailAddress)-[:BELONGS_TO]->(u:User {name: $name})
|
||||
RETURN email
|
||||
`
|
||||
await mutate({ mutation, variables })
|
||||
@ -281,7 +281,7 @@ describe('SignupVerification', () => {
|
||||
|
||||
it('marks the EmailAddress as primary', async () => {
|
||||
const cypher = `
|
||||
MATCH(email:EmailAddress)<-[:PRIMARY_EMAIL]-(u:User {name: {name}})
|
||||
MATCH(email:EmailAddress)<-[:PRIMARY_EMAIL]-(u:User {name: $name})
|
||||
RETURN email
|
||||
`
|
||||
await mutate({ mutation, variables })
|
||||
|
||||
@ -13,11 +13,11 @@ export default {
|
||||
MATCH (resource {id: $resourceId})
|
||||
WHERE resource:User OR resource:Post OR resource:Comment
|
||||
MERGE (resource)<-[:BELONGS_TO]-(report:Report {closed: false})
|
||||
ON CREATE SET report.id = randomUUID(), report.createdAt = $createdAt, report.updatedAt = report.createdAt, report.rule = 'latestReviewUpdatedAtRules', report.disable = resource.disabled, report.closed = false
|
||||
ON CREATE SET report.id = randomUUID(), report.createdAt = $createdAt, report.updatedAt = $createdAt, report.rule = 'latestReviewUpdatedAtRules', report.disable = resource.disabled, report.closed = false
|
||||
WITH submitter, resource, report
|
||||
CREATE (report)<-[filed:FILED {createdAt: $createdAt, reasonCategory: $reasonCategory, reasonDescription: $reasonDescription}]-(submitter)
|
||||
|
||||
WITH filed, report, resource {.*, __typename: filter(l IN labels(resource) WHERE l IN ['Post', 'Comment', 'User'])[0]} AS finalResource
|
||||
WITH filed, report, resource {.*, __typename: [l IN labels(resource) WHERE l IN ['Post', 'Comment', 'User']][0]} AS finalResource
|
||||
RETURN filed {.*, reportId: report.id, resource: properties(finalResource)} AS filedReport
|
||||
`,
|
||||
{
|
||||
@ -92,8 +92,8 @@ export default {
|
||||
[(submitter:User)-[filed:FILED]->(report) | filed {.*, submitter: properties(submitter)} ] as filed,
|
||||
[(moderator:User)-[reviewed:REVIEWED]->(report) | reviewed {.*, moderator: properties(moderator)} ] as reviewed,
|
||||
[(resource)<-[:WROTE]-(author:User) | author {.*} ] as optionalAuthors,
|
||||
[(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post {.*, author: properties(author), postType: filter(l IN labels(post) WHERE NOT l = "Post")} ] as optionalCommentedPosts,
|
||||
resource {.*, __typename: filter(l IN labels(resource) WHERE l IN ['Post', 'Comment', 'User'])[0] } as resourceWithType
|
||||
[(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post {.*, author: properties(author), postType: [l IN labels(post) WHERE NOT l = 'Post']} ] as optionalCommentedPosts,
|
||||
resource {.*, __typename: [l IN labels(resource) WHERE l IN ['Post', 'Comment', 'User']][0] } as resourceWithType
|
||||
WITH report, optionalAuthors, optionalCommentedPosts, reviewed, filed,
|
||||
resourceWithType {.*, post: optionalCommentedPosts[0], author: optionalAuthors[0] } as finalResource
|
||||
RETURN report {.*, resource: finalResource, filed: filed, reviewed: reviewed }
|
||||
|
||||
@ -12,7 +12,7 @@ const cypherTemplate = (setup) => `
|
||||
RETURN
|
||||
${setup.returnClause}
|
||||
AS result
|
||||
SKIP $skip
|
||||
SKIP toInteger($skip)
|
||||
${setup.limit}
|
||||
`
|
||||
|
||||
@ -45,7 +45,7 @@ const searchPostsSetup = {
|
||||
clickedCount: toString(resource.clickedCount),
|
||||
viewedTeaserCount: toString(resource.viewedTeaserCount)
|
||||
}`,
|
||||
limit: 'LIMIT $limit',
|
||||
limit: 'LIMIT toInteger($limit)',
|
||||
}
|
||||
|
||||
const searchUsersSetup = {
|
||||
@ -54,7 +54,7 @@ const searchUsersSetup = {
|
||||
whereClause: simpleWhereClause,
|
||||
withClause: '',
|
||||
returnClause: `resource {.*, __typename: 'User'}`,
|
||||
limit: 'LIMIT $limit',
|
||||
limit: 'LIMIT toInteger($limit)',
|
||||
}
|
||||
|
||||
const searchHashtagsSetup = {
|
||||
@ -63,7 +63,7 @@ const searchHashtagsSetup = {
|
||||
whereClause: simpleWhereClause,
|
||||
withClause: '',
|
||||
returnClause: `resource {.*, __typename: 'Tag'}`,
|
||||
limit: 'LIMIT $limit',
|
||||
limit: 'LIMIT toInteger($limit)',
|
||||
}
|
||||
|
||||
const searchGroupsSetup = {
|
||||
@ -78,7 +78,7 @@ const searchGroupsSetup = {
|
||||
OR membership.role IN ['usual', 'admin', 'owner'])`,
|
||||
withClause: 'WITH resource, membership',
|
||||
returnClause: `resource { .*, myRole: membership.role, __typename: 'Group' }`,
|
||||
limit: 'LIMIT $limit',
|
||||
limit: 'LIMIT toInteger($limit)',
|
||||
}
|
||||
|
||||
const countSetup = {
|
||||
|
||||
@ -81,7 +81,7 @@ export default {
|
||||
muteUser: async (_parent, params, context, _resolveInfo) => {
|
||||
const { user: currentUser } = context
|
||||
if (currentUser.id === params.id) return null
|
||||
await neode.cypher(
|
||||
await neode.writeCypher(
|
||||
`
|
||||
MATCH(u:User {id: $currentUser.id})-[previousRelationship:FOLLOWS]->(b:User {id: $params.id})
|
||||
DELETE previousRelationship
|
||||
@ -98,7 +98,7 @@ export default {
|
||||
unmuteUser: async (_parent, params, context, _resolveInfo) => {
|
||||
const { user: currentUser } = context
|
||||
if (currentUser.id === params.id) return null
|
||||
await neode.cypher(
|
||||
await neode.writeCypher(
|
||||
`
|
||||
MATCH(u:User {id: $currentUser.id})-[previousRelationship:MUTED]->(b:User {id: $params.id})
|
||||
DELETE previousRelationship
|
||||
@ -319,7 +319,7 @@ export default {
|
||||
email: async (parent, params, context, resolveInfo) => {
|
||||
if (typeof parent.email !== 'undefined') return parent.email
|
||||
const { id } = parent
|
||||
const statement = `MATCH(u:User {id: {id}})-[:PRIMARY_EMAIL]->(e:EmailAddress) RETURN e`
|
||||
const statement = `MATCH(u:User {id: $id})-[:PRIMARY_EMAIL]->(e:EmailAddress) RETURN e`
|
||||
const result = await neode.cypher(statement, { id })
|
||||
const [{ email }] = result.records.map((r) => r.get('e').properties)
|
||||
return email
|
||||
|
||||
@ -178,7 +178,7 @@ type Post {
|
||||
group: Group @relation(name: "IN", direction: "OUT")
|
||||
|
||||
postType: [PostType]
|
||||
@cypher(statement: "RETURN filter(l IN labels(this) WHERE NOT l = 'Post')")
|
||||
@cypher(statement: "RETURN [l IN labels(this) WHERE NOT l = 'Post']")
|
||||
|
||||
eventLocationName: String
|
||||
eventLocation: Location @cypher(statement: "MATCH (this)-[:IS_IN]->(l:Location) RETURN l")
|
||||
|
||||
@ -3,7 +3,7 @@ import { getNeode } from '../../backend/build/db/neo4j'
|
||||
|
||||
const neodeInstance = getNeode()
|
||||
|
||||
beforeEach(() => cy.then(() => neodeInstance.cypher('MATCH (everything) DETACH DELETE everything;')))
|
||||
beforeEach(() => cy.then(() => neodeInstance.writeCypher('MATCH (everything) DETACH DELETE everything;')))
|
||||
|
||||
Cypress.Commands.add('neode', () => {
|
||||
return neodeInstance
|
||||
|
||||
@ -18,4 +18,6 @@ data:
|
||||
NEO4J_dbms_memory_heap_max__size: "{{ .Values.NEO4J.DBMS_MEMORY_HEAP_MAX_SIZE }}"
|
||||
NEO4J_dbms_memory_pagecache_size: "{{ .Values.NEO4J.DBMS_MEMORY_PAGECACHE_SIZE }}"
|
||||
NEO4J_dbms_security_procedures_unrestricted: "{{ .Values.NEO4J.DBMS_SECURITY_PROCEDURES_UNRESTRICTED }}"
|
||||
NEO4J_dbms_allow__format__migration: true
|
||||
NEO4J_dbms_allow__upgrade: true
|
||||
NEO4J_apoc_import_file_enabled: "{{ .Values.NEO4J.APOC_IMPORT_FILE_ENABLED }}"
|
||||
@ -111,6 +111,8 @@ services:
|
||||
# TODO: This sounds scary for a production environment
|
||||
- NEO4J_AUTH=none
|
||||
- NEO4J_dbms_security_procedures_unrestricted=algo.*,apoc.*
|
||||
- NEO4J_dbms_allow__format__migration=true
|
||||
- NEO4J_dbms_allow__upgrade=true
|
||||
# Uncomment following line for Neo4j Enterprise version instead of Community version
|
||||
# TODO: clarify if that is the only thing needed to unlock the Enterprise version
|
||||
# - NEO4J_ACCEPT_LICENSE_AGREEMENT=yes
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
##################################################################################
|
||||
# COMMUNITY ######################################################################
|
||||
##################################################################################
|
||||
FROM amd64/neo4j:3.5.14 as community
|
||||
FROM amd64/neo4j:4.4-community as community
|
||||
|
||||
# ENVs
|
||||
## We Cannot do `$(date -u +'%Y-%m-%dT%H:%M:%SZ')` here so we use unix timestamp=0
|
||||
@ -31,15 +31,15 @@ LABEL maintainer="devops@ocelot.social"
|
||||
## install: wget, htop (TODO: why do we need htop?)
|
||||
RUN apt-get update && apt-get -y install wget htop
|
||||
## install: apoc plugin for neo4j
|
||||
RUN wget https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/3.5.0.4/apoc-3.5.0.4-all.jar -P plugins/
|
||||
RUN wget https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/4.4.0.17/apoc-4.4.0.17-all.jar -P plugins/
|
||||
|
||||
##################################################################################
|
||||
# ENTERPRISE #####################################################################
|
||||
##################################################################################
|
||||
FROM neo4j:3.5.14-enterprise as enterprise
|
||||
FROM neo4j:4.4-enterprise as enterprise
|
||||
|
||||
# Install Additional Software
|
||||
## install: wget, htop (TODO: why do we need htop?)
|
||||
RUN apt-get update && apt-get -y install wget htop
|
||||
## install: apoc plugin for neo4j
|
||||
RUN wget https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/3.5.0.4/apoc-3.5.0.4-all.jar -P plugins/
|
||||
RUN wget https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/4.4.0.17/apoc-4.4.0.17-all.jar -P plugins/
|
||||
Loading…
x
Reference in New Issue
Block a user