Skip to content

Commit 0d84113

Browse files
committed
Add migration
1 parent e5e5089 commit 0d84113

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 { NormalizeCreatorMigration } from './migrations/normalize-creator.migration';
89

910
@Module({
1011
imports: [AuthorizationModule],
@@ -16,6 +17,7 @@ import { AdminService } from './admin.service';
1617
// and each will only use their own.
1718
AdminEdgeDBRepository,
1819
),
20+
NormalizeCreatorMigration,
1921
],
2022
})
2123
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-16T19:00:00')
4+
export class NormalizeCreatorMigration 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)-[r:creator { active: true }]->(oldCreatorProp:Property)
11+
where not exists { (:User { id: oldCreatorProp.value }) }
12+
create (bn)-[:creator { active: true, createdAt: r.createdAt }]->(user)
13+
detach delete oldCreatorProp
14+
`.executeAndLogStats();
15+
16+
await this.db.query().raw`
17+
match (bn)-[r:creator { active: true }]->(oldCreatorProp:Property)
18+
with bn, r, oldCreatorProp
19+
match (user:User { id: oldCreatorProp.value })
20+
create (bn)-[:creator { active: true, createdAt: r.createdAt }]->(user)
21+
detach delete oldCreatorProp
22+
`.executeAndLogStats();
23+
}
24+
}

0 commit comments

Comments
 (0)