From e3437010574294b2569529e3740c3e2c3fca147f Mon Sep 17 00:00:00 2001 From: roschaefer Date: Thu, 23 Jan 2020 17:38:31 +0100 Subject: [PATCH] Reverted a couple changes by @mattwr18 We have to figure out if `mergeRels: true` is actually avoiding duplicate relationships :thinking:. Before: (l1)-[:IS_IN]->(l2) (l1)-[:IS_IN]->(l3) After: (l1)-[:IS_IN]->(new) (l1)-[:IS_IN]->(new) --- backend/README.md | 4 ++-- backend/package.json | 2 +- backend/src/db/migrate/store.js | 12 +++++++----- .../20200123150110-merge_duplicate_location_nodes.js | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/backend/README.md b/backend/README.md index 2ad53ac08..7fd49faf8 100644 --- a/backend/README.md +++ b/backend/README.md @@ -120,7 +120,7 @@ you have to migrate your data e.g. because your data modeling has changed. {% tab title="Docker" %} Generate a data migration file: ```bash -$ docker-compose exec backend yarn run db:migrate:create your_data_migration --date-format 'yyyymmddHHmmss' --template-file src/db/migrate/template.js +$ docker-compose exec backend yarn run db:migrate:create your_data_migration # Edit the file in ./src/db/migrations/ ``` @@ -132,7 +132,7 @@ $ docker-compose exec backend yarn run db:migrate up {% tab title="Without Docker" %} Generate a data migration file: ```bash -$ yarn run db:migrate:create your_data_migration --date-format 'yyyymmddHHmmss' --template-file src/db/migrate/template.js +$ yarn run db:migrate:create your_data_migration # Edit the file in ./src/db/migrations/ ``` diff --git a/backend/package.json b/backend/package.json index 042f96339..e44f325ed 100644 --- a/backend/package.json +++ b/backend/package.json @@ -16,7 +16,7 @@ "db:reset": "yarn run db:clean", "db:seed": "babel-node src/db/seed.js", "db:migrate": "yarn run __migrate --store ./src/db/migrate/store.js", - "db:migrate:create": "yarn run __migrate --template-file ./src/db/migrate/template.js create" + "db:migrate:create": "yarn run __migrate --template-file ./src/db/migrate/template.js --date-format 'yyyymmddHHmmss' create" }, "author": "Human Connection gGmbH", "license": "MIT", diff --git a/backend/src/db/migrate/store.js b/backend/src/db/migrate/store.js index f66ae91d8..8bc73b511 100644 --- a/backend/src/db/migrate/store.js +++ b/backend/src/db/migrate/store.js @@ -35,7 +35,7 @@ class Store { const session = driver.session() const readTxResultPromise = session.readTransaction(async txc => { const result = await txc.run( - 'MATCH (migration:Migration) RETURN migration {.*} ORDER BY migration.migratedAt DESC', + 'MATCH (migration:Migration) RETURN migration {.*} ORDER BY migration.timestamp DESC', ) return result.records.map(r => r.get('migration')) }) @@ -65,14 +65,16 @@ class Store { const writeTxResultPromise = session.writeTransaction(txc => { return Promise.all( migrations.map(async migration => { - const { title, description } = migration - const properties = { title, description } + const { title, description, timestamp } = migration + const properties = { title, description, timestamp } const migrationResult = await txc.run( ` MERGE (migration:Migration { title: $properties.title }) - ON CREATE SET migration += $properties, + ON MATCH SET + migration += $properties + ON CREATE SET + migration += $properties, migration.migratedAt = toString(datetime()) - RETURN migration `, { properties }, ) diff --git a/backend/src/db/migrations/20200123150110-merge_duplicate_location_nodes.js b/backend/src/db/migrations/20200123150110-merge_duplicate_location_nodes.js index 9bd3d4d3b..b2d6b260f 100644 --- a/backend/src/db/migrations/20200123150110-merge_duplicate_location_nodes.js +++ b/backend/src/db/migrations/20200123150110-merge_duplicate_location_nodes.js @@ -33,7 +33,7 @@ export function up(next) { ` MATCH(location:Location {id: $locationId}), (location2:Location {id: $locationId}) WHERE location.id = location2.id AND id(location) < id(location2) - CALL apoc.refactor.mergeNodes([location, location2], { properties: 'combine' }) YIELD node as updatedLocation + CALL apoc.refactor.mergeNodes([location, location2], { properties: 'combine', mergeRels: true }) YIELD node as updatedLocation RETURN location {.*},updatedLocation {.*} `, { locationId },