From 98a4521ecc36cf44deebb2ba02fbbdf96d53b8c2 Mon Sep 17 00:00:00 2001 From: roschaefer Date: Mon, 20 Jan 2020 11:28:36 +0100 Subject: [PATCH] Add back missing search constraint --- backend/src/db/migrate/store.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/backend/src/db/migrate/store.js b/backend/src/db/migrate/store.js index 9984b3971..b2d65a0f2 100644 --- a/backend/src/db/migrate/store.js +++ b/backend/src/db/migrate/store.js @@ -3,10 +3,27 @@ import { getDriver, getNeode } from '../../db/neo4j' class Store { async init(fn) { const neode = getNeode() - await getNeode().schema.install() + const { driver } = neode + const session = driver.session() // eslint-disable-next-line no-console - console.log('Successfully created database indices and constraints!') - neode.driver.close() + const writeTxResultPromise = session.writeTransaction(async txc => { + await txc.run('CALL apoc.schema.assert({},{},true)') // drop all indices + return Promise.all([ + 'CALL db.index.fulltext.createNodeIndex("post_fulltext_search",["Post"],["title", "content"])', + 'CALL db.index.fulltext.createNodeIndex("user_fulltext_search",["User"],["name", "slug"])' + ].map(statement => txc.run(statement))) + }) + try { + await writeTxResultPromise + await getNeode().schema.install() + console.log('Successfully created database indices and constraints!') + } catch (error) { + console.log(error) // eslint-disable-line no-console + } finally { + session.close() + driver.close() + fn() + } } async load(fn) {