Skip to content

Commit 0784c59

Browse files
authored
[Neo4j] Migrate creator on BaseNode to normalized relationship (#3178)
1 parent 89c82a9 commit 0784c59

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/components/admin/admin.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AdminEdgeDBRepository } from './admin.edgedb.repository';
55
import { AdminEdgeDBService } from './admin.edgedb.service';
66
import { AdminRepository } from './admin.repository';
77
import { AdminService } from './admin.service';
8+
import { NormalizeCreatorBaseNodeMigration } from './migrations/normalize-creator-base-node.migration';
89
import { NormalizeCreatorMigration } from './migrations/normalize-creator.migration';
910

1011
@Module({
@@ -18,6 +19,7 @@ import { NormalizeCreatorMigration } from './migrations/normalize-creator.migrat
1819
AdminEdgeDBRepository,
1920
),
2021
NormalizeCreatorMigration,
22+
NormalizeCreatorBaseNodeMigration,
2123
],
2224
})
2325
export class AdminModule {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { BaseMigration, Migration } from '~/core/database';
2+
3+
@Migration('2024-04-18T09:00:00')
4+
export class NormalizeCreatorBaseNodeMigration extends BaseMigration {
5+
async up() {
6+
// Handle RootUser first specially.
7+
// Since denormalized creator IDs for RootUser currently reference a non-existent user ID
8+
await this.db.query().raw`
9+
match (user:RootUser)
10+
match (bn:BaseNode)
11+
where bn.creator is not null and not exists { (:User { id: bn.creator }) }
12+
create (bn)-[:creator { active: true, createdAt: bn.createdAt }]->(user)
13+
set bn.creator = null
14+
`.executeAndLogStats();
15+
16+
await this.db.query().raw`
17+
match (bn:BaseNode)
18+
where bn.creator is not null
19+
match (user:User { id: bn.creator })
20+
create (bn)-[:creator { active: true, createdAt: bn.createdAt }]->(user)
21+
set bn.creator = null
22+
`.executeAndLogStats();
23+
}
24+
}

0 commit comments

Comments
 (0)