diff --git a/backend/README.md b/backend/README.md index 7fd49faf8..2ad53ac08 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 +$ docker-compose exec backend yarn run db:migrate:create your_data_migration --date-format 'yyyymmddHHmmss' --template-file src/db/migrate/template.js # 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 +$ yarn run db:migrate:create your_data_migration --date-format 'yyyymmddHHmmss' --template-file src/db/migrate/template.js # Edit the file in ./src/db/migrations/ ``` diff --git a/backend/src/db/migrate/store.js b/backend/src/db/migrate/store.js index 81df47708..f66ae91d8 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.createdAt DESC', + 'MATCH (migration:Migration) RETURN migration {.*} ORDER BY migration.migratedAt DESC', ) return result.records.map(r => r.get('migration')) }) @@ -71,7 +71,7 @@ class Store { ` MERGE (migration:Migration { title: $properties.title }) ON CREATE SET migration += $properties, - migration.createdAt = toString(datetime()) + migration.migratedAt = toString(datetime()) RETURN migration `, { properties }, diff --git a/backend/src/db/migrations/1579387929122-merge_duplicate_user_accounts.js b/backend/src/db/migrations/20200123150105-merge_duplicate_user_accounts.js similarity index 100% rename from backend/src/db/migrations/1579387929122-merge_duplicate_user_accounts.js rename to backend/src/db/migrations/20200123150105-merge_duplicate_user_accounts.js diff --git a/backend/src/db/migrations/1579387929111-merge_duplicate_location_nodes.js b/backend/src/db/migrations/20200123150110-merge_duplicate_location_nodes.js similarity index 85% rename from backend/src/db/migrations/1579387929111-merge_duplicate_location_nodes.js rename to backend/src/db/migrations/20200123150110-merge_duplicate_location_nodes.js index 390bfd935..9bd3d4d3b 100644 --- a/backend/src/db/migrations/1579387929111-merge_duplicate_location_nodes.js +++ b/backend/src/db/migrations/20200123150110-merge_duplicate_location_nodes.js @@ -24,19 +24,19 @@ export function up(next) { .records() .pipe( map(record => { - const { id: locationIds } = record.get('location') - return { locationIds } + const { id: locationId } = record.get('location') + return { locationId } }), - mergeMap(({ locationIds }) => { + mergeMap(({ locationId }) => { return transaction .run( ` - MATCH(location:Location {id: $locationIds}), (location2:Location {id: $locationIds}) + 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', mergeRels: true }) YIELD node as updatedLocation + CALL apoc.refactor.mergeNodes([location, location2], { properties: 'combine' }) YIELD node as updatedLocation RETURN location {.*},updatedLocation {.*} `, - { locationIds }, + { locationId }, ) .records() .pipe( diff --git a/backend/src/models/Migration.js b/backend/src/models/Migration.js index 1b697c8ad..8f16b800a 100644 --- a/backend/src/models/Migration.js +++ b/backend/src/models/Migration.js @@ -1,5 +1,5 @@ export default { title: { type: 'string', primary: true, token: true }, description: { type: 'string' }, - createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, + migratedAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, }