mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Update docs, follow @roschaefer suggestions
- create command should be run with --date-format to be more human readable, and --template-file to use our template instead of migrate's default - rename migrations - rename createdAt to migratedAt to remove ambiguity - do not merge relationships for Location nodes as we don't want to create duplicate relationships - use singular locationId as it's iterating one at a time
This commit is contained in:
parent
f3784c5f50
commit
28dae1f854
@ -120,7 +120,7 @@ you have to migrate your data e.g. because your data modeling has changed.
|
|||||||
{% tab title="Docker" %}
|
{% tab title="Docker" %}
|
||||||
Generate a data migration file:
|
Generate a data migration file:
|
||||||
```bash
|
```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/
|
# Edit the file in ./src/db/migrations/
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ $ docker-compose exec backend yarn run db:migrate up
|
|||||||
{% tab title="Without Docker" %}
|
{% tab title="Without Docker" %}
|
||||||
Generate a data migration file:
|
Generate a data migration file:
|
||||||
```bash
|
```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/
|
# Edit the file in ./src/db/migrations/
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -35,7 +35,7 @@ class Store {
|
|||||||
const session = driver.session()
|
const session = driver.session()
|
||||||
const readTxResultPromise = session.readTransaction(async txc => {
|
const readTxResultPromise = session.readTransaction(async txc => {
|
||||||
const result = await txc.run(
|
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'))
|
return result.records.map(r => r.get('migration'))
|
||||||
})
|
})
|
||||||
@ -71,7 +71,7 @@ class Store {
|
|||||||
`
|
`
|
||||||
MERGE (migration:Migration { title: $properties.title })
|
MERGE (migration:Migration { title: $properties.title })
|
||||||
ON CREATE SET migration += $properties,
|
ON CREATE SET migration += $properties,
|
||||||
migration.createdAt = toString(datetime())
|
migration.migratedAt = toString(datetime())
|
||||||
RETURN migration
|
RETURN migration
|
||||||
`,
|
`,
|
||||||
{ properties },
|
{ properties },
|
||||||
|
|||||||
@ -24,19 +24,19 @@ export function up(next) {
|
|||||||
.records()
|
.records()
|
||||||
.pipe(
|
.pipe(
|
||||||
map(record => {
|
map(record => {
|
||||||
const { id: locationIds } = record.get('location')
|
const { id: locationId } = record.get('location')
|
||||||
return { locationIds }
|
return { locationId }
|
||||||
}),
|
}),
|
||||||
mergeMap(({ locationIds }) => {
|
mergeMap(({ locationId }) => {
|
||||||
return transaction
|
return transaction
|
||||||
.run(
|
.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)
|
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 {.*}
|
RETURN location {.*},updatedLocation {.*}
|
||||||
`,
|
`,
|
||||||
{ locationIds },
|
{ locationId },
|
||||||
)
|
)
|
||||||
.records()
|
.records()
|
||||||
.pipe(
|
.pipe(
|
||||||
@ -1,5 +1,5 @@
|
|||||||
export default {
|
export default {
|
||||||
title: { type: 'string', primary: true, token: true },
|
title: { type: 'string', primary: true, token: true },
|
||||||
description: { type: 'string' },
|
description: { type: 'string' },
|
||||||
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
|
migratedAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user