Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/components/project/handlers/set-department-id.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,21 @@ export class SetDepartmentId implements IEventHandler<SubscribedEvent> {
// Get used IDs
.subQuery((sub) =>
sub
.match([
node('', 'Project'),
relation('out', '', 'departmentId', ACTIVE),
node('deptIdNode', 'Property'),
])
.where({ 'deptIdNode.value': not(isNull()) })
.return(collect('deptIdNode.value').as('used')),
.subQuery((sub2) =>
sub2
.match([
node('', 'Project'),
relation('out', '', 'departmentId', ACTIVE),
node('deptIdNode', 'Property'),
])
.where({ 'deptIdNode.value': not(isNull()) })
.return('deptIdNode.value as id')
.union()
.match(node('external', 'ExternalDepartmentId'))
.return('external.departmentId as id'),
)
.return(collect('id').as('used')),
)
// Distill to available
.with('[id in enumerated where not id in used][0] as next')
// collapse cardinality to zero if none available
.raw('unwind next as nextId')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { node } from 'cypher-query-builder';
import { readFile } from 'node:fs/promises';
import { BaseMigration, Migration } from '~/core/database';
import { apoc, variable } from '~/core/database/query';

interface ExternalDepartmentId {
id: string;
name?: string;
}

@Migration('2025-09-17T09:00:00')
export class CreateUsedDeptIdListMigration extends BaseMigration {
async up() {
const intaactFilePath = new URL(
'../../../../../.vscode/localFiles/All-Department-Ids-From-Intaact.csv',
import.meta.url,
);
const cordFilePath = new URL(
'../../../../../.vscode/localFiles/prod_deptIds_ids_only.csv',
import.meta.url,
);

const intaactFileContent = await readFile(intaactFilePath, 'utf-8');
const cordFileContent = await readFile(cordFilePath, 'utf-8');

const intaactRows = intaactFileContent.trim().split(/\r?\n/).slice(1); // Skip header
const cordRows = cordFileContent.trim().split(/\r?\n/).slice(1); // Skip header

const intaactList: ExternalDepartmentId[] = intaactRows.flatMap((row) => {
const [id, name] = row.split(',');
return id ? { id, name } : [];
});

const prunedIntaactList = intaactList.flatMap((row) =>
!cordRows.includes(row.id) ? row : [],
);

await this.db
.query()
.unwind(prunedIntaactList, 'dept')
.create(node('external', 'ExternalDepartmentId'))
.setValues({
'external.id': variable(apoc.create.uuid()),
'external.departmentId': variable('dept.id'),
'external.name': variable('dept.name'),
'external.createdAt': variable('datetime()'),
})
.return('count(external) as created')
.executeAndLogStats();
}
}
2 changes: 2 additions & 0 deletions src/components/project/project.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ProjectEngagementConnectionResolver } from './engagement-connection.res
import { FinancialApproverModule } from './financial-approver/financial-approver.module';
import * as handlers from './handlers';
import { InternshipProjectResolver } from './internship-project.resolver';
import { CreateUsedDeptIdListMigration } from './migrations/create-used-dept-id-list.migration';
import { FixDeptIdLabelMigration } from './migrations/fix-dept-id-label.migration';
import { RenameTranslationToMomentumMigration } from './migrations/rename-translation-to-momentum.migration';
import { ProjectEngagementIdResolvers } from './project-engagement-id.resolver';
Expand Down Expand Up @@ -55,6 +56,7 @@ import { ProjectWorkflowModule } from './workflow/project-workflow.module';
...Object.values(ConcreteRepos),
ProjectLoader,
...Object.values(handlers),
CreateUsedDeptIdListMigration,
RenameTranslationToMomentumMigration,
FixDeptIdLabelMigration,
],
Expand Down