|
| 1 | +/** |
| 2 | + * @typedef {import('typeorm').MigrationInterface} MigrationInterface |
| 3 | + * @typedef {import('typeorm').QueryRunner} QueryRunner |
| 4 | + */ |
| 5 | + |
| 6 | +/** |
| 7 | + * @class |
| 8 | + * @implements {MigrationInterface} |
| 9 | + */ |
| 10 | +module.exports = class SetFinanceFarmAmlRules1768503536967 { |
| 11 | + name = 'SetFinanceFarmAmlRules1768503536967' |
| 12 | + |
| 13 | + /** |
| 14 | + * Add RULE_15 (Force Manual Check) to FinanceFarm wallet (ID 42). |
| 15 | + * |
| 16 | + * Current state: amlRules = '2' (RULE_2: KycLevel 30) |
| 17 | + * New state: amlRules = '2;15' (RULE_2 + RULE_15: Force Manual Check) |
| 18 | + * |
| 19 | + * @param {QueryRunner} queryRunner |
| 20 | + */ |
| 21 | + async up(queryRunner) { |
| 22 | + // Only add RULE_15 if it's not already present |
| 23 | + // Check for exact match: '15', '15;...', '...;15', '...;15;...' |
| 24 | + await queryRunner.query(` |
| 25 | + UPDATE "dbo"."wallet" |
| 26 | + SET "amlRules" = CASE |
| 27 | + WHEN "amlRules" IS NULL OR "amlRules" = '' OR "amlRules" = '0' THEN '15' |
| 28 | + WHEN "amlRules" = '15' THEN "amlRules" |
| 29 | + WHEN "amlRules" LIKE '15;%' THEN "amlRules" |
| 30 | + WHEN "amlRules" LIKE '%;15' THEN "amlRules" |
| 31 | + WHEN "amlRules" LIKE '%;15;%' THEN "amlRules" |
| 32 | + ELSE "amlRules" + ';15' |
| 33 | + END |
| 34 | + WHERE "id" = 42 AND "name" = 'FinanceFarm' |
| 35 | + `); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Remove RULE_15 from FinanceFarm wallet. |
| 40 | + * |
| 41 | + * @param {QueryRunner} queryRunner |
| 42 | + */ |
| 43 | + async down(queryRunner) { |
| 44 | + // Remove RULE_15 from amlRules (handles: '15', '2;15', '15;2', '2;15;3') |
| 45 | + await queryRunner.query(` |
| 46 | + UPDATE "dbo"."wallet" |
| 47 | + SET "amlRules" = CASE |
| 48 | + WHEN "amlRules" = '15' THEN '0' |
| 49 | + WHEN "amlRules" LIKE '15;%' THEN STUFF("amlRules", 1, 3, '') |
| 50 | + WHEN "amlRules" LIKE '%;15' THEN LEFT("amlRules", LEN("amlRules") - 3) |
| 51 | + WHEN "amlRules" LIKE '%;15;%' THEN REPLACE("amlRules", ';15;', ';') |
| 52 | + ELSE "amlRules" |
| 53 | + END |
| 54 | + WHERE "id" = 42 AND "name" = 'FinanceFarm' |
| 55 | + `); |
| 56 | + } |
| 57 | +} |
0 commit comments