Skip to content

Commit f1d88cd

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

File tree

2 files changed

+59
-0
lines changed

2 files changed

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

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)