Skip to content

Commit f5ace7b

Browse files
authored
Merge pull request #3096 from DFXswiss/develop
Release: develop -> main
2 parents f9e734b + 3679e2f commit f5ace7b

1 file changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**
2+
* @typedef {import('typeorm').MigrationInterface} MigrationInterface
3+
* @typedef {import('typeorm').QueryRunner} QueryRunner
4+
*/
5+
6+
/**
7+
* Reset KYC level for users with expired AML and no reactivation.
8+
*
9+
* Users with KycLevel >= 30 who have amlListExpiredDate set but no
10+
* amlListReactivatedDate should not have elevated KYC levels, as their
11+
* AML verification has expired and was never renewed.
12+
*
13+
* This migration sets their KycLevel back to 20 (basic level).
14+
*
15+
* IMPORTANT: Excludes 43 users who have a completed DfxApproval after their
16+
* amlListExpiredDate - these users legitimately re-verified but the
17+
* amlListReactivatedDate was not set (separate bug to fix).
18+
*
19+
* Affected users: 318 (as of 2026-01-31)
20+
* Excluded users: 43 (have DfxApproval after expiry)
21+
*
22+
* @class
23+
* @implements {MigrationInterface}
24+
*/
25+
module.exports = class ResetExpiredAmlKycLevel1769200000000 {
26+
name = 'ResetExpiredAmlKycLevel1769200000000';
27+
28+
/**
29+
* @param {QueryRunner} queryRunner
30+
*/
31+
async up(queryRunner) {
32+
// First, log the count of affected users for verification
33+
const result = await queryRunner.query(`
34+
SELECT COUNT(*) as count
35+
FROM "dbo"."user_data"
36+
WHERE "kycLevel" >= 30
37+
AND "amlListExpiredDate" IS NOT NULL
38+
AND "amlListReactivatedDate" IS NULL
39+
AND NOT EXISTS (
40+
SELECT 1 FROM "dbo"."kyc_step"
41+
WHERE "userDataId" = "user_data"."id"
42+
AND "name" = 'DfxApproval'
43+
AND "status" = 'Completed'
44+
AND "created" > "user_data"."amlListExpiredDate"
45+
)
46+
`);
47+
console.log(`Resetting KYC level for ${result[0].count} users with expired AML and no reactivation`);
48+
49+
// Update KycLevel to 20 for affected users (excluding those with DfxApproval after expiry)
50+
await queryRunner.query(`
51+
UPDATE "dbo"."user_data"
52+
SET "kycLevel" = 20
53+
WHERE "kycLevel" >= 30
54+
AND "amlListExpiredDate" IS NOT NULL
55+
AND "amlListReactivatedDate" IS NULL
56+
AND NOT EXISTS (
57+
SELECT 1 FROM "dbo"."kyc_step"
58+
WHERE "userDataId" = "user_data"."id"
59+
AND "name" = 'DfxApproval'
60+
AND "status" = 'Completed'
61+
AND "created" > "user_data"."amlListExpiredDate"
62+
)
63+
`);
64+
}
65+
66+
/**
67+
* @param {QueryRunner} queryRunner
68+
*/
69+
async down(queryRunner) {
70+
// Note: This down migration cannot fully restore the original state
71+
// as we don't know the original KycLevel values. This sets them to 50
72+
// as a reasonable default for users who had completed KYC.
73+
console.log('Warning: Down migration sets KycLevel to 50, original values are not preserved');
74+
75+
await queryRunner.query(`
76+
UPDATE "dbo"."user_data"
77+
SET "kycLevel" = 50
78+
WHERE "kycLevel" = 20
79+
AND "amlListExpiredDate" IS NOT NULL
80+
AND "amlListReactivatedDate" IS NULL
81+
AND "kycStatus" = 'Completed'
82+
AND NOT EXISTS (
83+
SELECT 1 FROM "dbo"."kyc_step"
84+
WHERE "userDataId" = "user_data"."id"
85+
AND "name" = 'DfxApproval'
86+
AND "status" = 'Completed'
87+
AND "created" > "user_data"."amlListExpiredDate"
88+
)
89+
`);
90+
}
91+
};

0 commit comments

Comments
 (0)