Skip to content

Commit

Permalink
feat: migration logic for org_dids and schema type (#946)
Browse files Browse the repository at this point in the history
* feat:migration script for did list

Signed-off-by: tipusinghaw <[email protected]>

* feat:schema support for W3C

Signed-off-by: tipusinghaw <[email protected]>

---------

Signed-off-by: tipusinghaw <[email protected]>
  • Loading branch information
tipusinghaw authored Aug 27, 2024
1 parent a96654b commit 0c0e4c1
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/api-gateway/src/connection/connection.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export class ConnectionController {
}

@Post('/orgs/:orgId/basic-message/:connectionId')
@ApiOperation({ summary: '', description: 'send question' })
@ApiOperation({ summary: 'Send basic message', description: 'Send basic message' })
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.ISSUER, OrgRoles.VERIFIER, OrgRoles.MEMBER, OrgRoles.HOLDER, OrgRoles.SUPER_ADMIN, OrgRoles.PLATFORM_ADMIN)
@ApiResponse({ status: HttpStatus.CREATED, description: 'Created', type: ApiResponseDto })
Expand Down
79 changes: 78 additions & 1 deletion libs/prisma-service/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,82 @@ const createUserRole = async (): Promise<void> => {
}
};

const migrateOrgAgentDids = async (): Promise<void> => {
try {
const orgAgents = await prisma.org_agents.findMany({
where: {
walletName: {
not: 'platform-admin'
}
}
});

const orgDids = orgAgents.map((agent) => agent.orgDid);

const existingDids = await prisma.org_dids.findMany({
where: {
did: {
in: orgDids
}
}
});

// If there are org DIDs that do not exist in org_dids table
if (orgDids.length !== existingDids.length) {
const newOrgAgents = orgAgents.filter(
(agent) => !existingDids.some((did) => did.did === agent.orgDid)
);

const newDidRecords = newOrgAgents.map((agent) => ({
orgId: agent.orgId,
did: agent.orgDid,
didDocument: agent.didDocument,
isPrimaryDid: true,
createdBy: agent.createdBy,
lastChangedBy: agent.lastChangedBy,
orgAgentId: agent.id
}));

const didInsertResult = await prisma.org_dids.createMany({
data: newDidRecords
});

logger.log(didInsertResult);
} else {
logger.log('No new DIDs to migrate in migrateOrgAgentDids');
}
} catch (error) {
logger.error('An error occurred during migrateOrgAgentDids:', error);
}
};

const addSchemaType = async (): Promise<void> => {
try {
const emptyTypeSchemaList = await prisma.schema.findMany({
where: {
OR: [
{ type: null },
{ type: '' }
]
}
});
if (0 < emptyTypeSchemaList.length) {
const updatePromises = emptyTypeSchemaList.map((schema) => prisma.schema.update({
where: { id: schema.id },
data: { type: 'indy' }
})
);
await Promise.all(updatePromises);

logger.log('Schemas updated successfully');
} else {
logger.log('No schemas to update');
}
} catch (error) {
logger.error('An error occurred during addSchemaType:', error);
}
};

async function main(): Promise<void> {

await createPlatformConfig();
Expand All @@ -388,9 +464,10 @@ async function main(): Promise<void> {
await createEcosystemConfig();
await createLedgerConfig();
await createUserRole();
await migrateOrgAgentDids();
await addSchemaType();
}


main()
.then(async () => {
await prisma.$disconnect();
Expand Down

0 comments on commit 0c0e4c1

Please sign in to comment.