Skip to content

Commit 3cd692f

Browse files
committed
Add migration to create department id blacklist
1 parent 9418846 commit 3cd692f

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { node } from 'cypher-query-builder';
2+
import { readFile } from 'node:fs/promises';
3+
import { BaseMigration, Migration } from '~/core/database';
4+
import { apoc, variable } from '~/core/database/query';
5+
6+
interface ExternalDepartmentId {
7+
id: string;
8+
name?: string;
9+
}
10+
11+
@Migration('2025-09-17T09:00:00')
12+
export class CreateUsedDeptIdListMigration extends BaseMigration {
13+
async up() {
14+
const intaactFilePath = new URL(
15+
'../../../../../.vscode/localFiles/All-Department-Ids-From-Intaact.csv',
16+
import.meta.url,
17+
);
18+
const cordFilePath = new URL(
19+
'../../../../../.vscode/localFiles/prod_deptIds_ids_only.csv',
20+
import.meta.url,
21+
);
22+
23+
const intaactFileContent = await readFile(intaactFilePath, 'utf-8');
24+
const cordFileContent = await readFile(cordFilePath, 'utf-8');
25+
26+
const intaactRows = intaactFileContent.trim().split(/\r?\n/).slice(1); // Skip header
27+
const cordRows = cordFileContent.trim().split(/\r?\n/).slice(1); // Skip header
28+
29+
const intaactList: ExternalDepartmentId[] = intaactRows.flatMap((row) => {
30+
const [id, name] = row.split(',');
31+
if (id) {
32+
return { id, name };
33+
}
34+
return [];
35+
});
36+
37+
const prunedIntaactList = intaactList.flatMap((row) =>
38+
!cordRows.includes(row.id) ? row : [],
39+
);
40+
41+
await this.db
42+
.query()
43+
.unwind(prunedIntaactList, 'dept')
44+
.create(node('blacklist', 'BlacklistDepartmentId'))
45+
.setValues({
46+
'blacklist.id': variable(apoc.create.uuid()),
47+
'blacklist.departmentId': variable('dept.id'),
48+
'blacklist.departmentName': variable('dept.name'),
49+
'blacklist.createdAt': Date.now(),
50+
'blacklist.createdBy': 'bulk_import',
51+
})
52+
.return('count(blacklist) as created')
53+
.executeAndLogStats();
54+
}
55+
}

src/components/project/project.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { ProjectEngagementConnectionResolver } from './engagement-connection.res
1414
import { FinancialApproverModule } from './financial-approver/financial-approver.module';
1515
import * as handlers from './handlers';
1616
import { InternshipProjectResolver } from './internship-project.resolver';
17+
import { CreateUsedDeptIdListMigration } from './migrations/create-used-dept-id-list.migration';
1718
import { FixDeptIdLabelMigration } from './migrations/fix-dept-id-label.migration';
1819
import { RenameTranslationToMomentumMigration } from './migrations/rename-translation-to-momentum.migration';
1920
import { ProjectEngagementIdResolvers } from './project-engagement-id.resolver';
@@ -55,6 +56,7 @@ import { ProjectWorkflowModule } from './workflow/project-workflow.module';
5556
...Object.values(ConcreteRepos),
5657
ProjectLoader,
5758
...Object.values(handlers),
59+
CreateUsedDeptIdListMigration,
5860
RenameTranslationToMomentumMigration,
5961
FixDeptIdLabelMigration,
6062
],

0 commit comments

Comments
 (0)