Skip to content

Commit

Permalink
fix: make seed mock script work again (#6003)
Browse files Browse the repository at this point in the history
* fix: make seed mock script work again

* fix: revert to abbreviated sequence name
  • Loading branch information
jannisvisser authored and Ruben committed Oct 31, 2024
1 parent be6d4ef commit 62a6df1
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export class MigrateDataChangesToEvent1708330965061
await queryRunner.query(
`DROP INDEX "121-service"."IDX_5c7356500932acbd5f76a787ce"`,
);
console.time('migrateData');
const manager = queryRunner.manager;
const eventRepo = manager.getRepository(EventEntity);
const keysToMigrate = ['fieldName', 'oldValue', 'newValue', 'reason'];
Expand Down Expand Up @@ -70,6 +69,5 @@ export class MigrateDataChangesToEvent1708330965061
await queryRunner.query(
`DROP TABLE IF EXISTS "121-service".registration_change_log `,
);
console.timeEnd('migrateData');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export class MigrateStatusChangesToEvent1708330966062
public async down(_queryRunner: QueryRunner): Promise<void> {}

private async migrateStatusChanges(queryRunner: QueryRunner): Promise<void> {
console.time('migrateStatusChanges');
const manager = queryRunner.manager;
const eventRepo = manager.getRepository(EventEntity);
const adminUser = await queryRunner.query(
Expand Down Expand Up @@ -75,6 +74,5 @@ export class MigrateStatusChangesToEvent1708330966062
});

await eventRepo.save(events, { chunk: 300 });
console.timeEnd('migrateStatusChanges');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export class RemoveStartedRegistrationState1713363871246
name = 'RemoveStartedRegistrationState1713363871246';

public async up(queryRunner: QueryRunner): Promise<void> {
console.time('RemoveStartedRegistrationState1713363871246');
await queryRunner.commitTransaction();

await queryRunner.query(`DELETE FROM "121-service".note WHERE "registrationId" IN
Expand All @@ -32,7 +31,6 @@ export class RemoveStartedRegistrationState1713363871246
);

await queryRunner.startTransaction();
console.timeEnd('RemoveStartedRegistrationState1713363871246');
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export class RemoveDeletedStateFromRegistration1714467563401
name = 'RemoveDeletedStateFromRegistration1714467563401';

public async up(queryRunner: QueryRunner): Promise<void> {
console.time('RemoveDeletedStateFromRegistration1714467563401');
await queryRunner.commitTransaction();

const queryCondition = `"fspId" is null AND "registrationStatus" = 'deleted'`;
Expand Down Expand Up @@ -44,7 +43,6 @@ export class RemoveDeletedStateFromRegistration1714467563401
);

await queryRunner.startTransaction();
console.timeEnd('RemoveDeletedStateFromRegistration1714467563401');
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand Down
10 changes: 9 additions & 1 deletion services/121-service/src/scripts/seed-mock-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,15 @@ export class SeedMockHelper {
for (const table of tables) {
const tableName = table.table_name;
if (!['custom_migration', 'typeorm_metadata'].includes(tableName)) {
const sequenceName = `${tableName}_id_seq`;
let sequenceName = `${tableName}_id_seq`;
// this sequences is created with an abbreviated name automatically, so this exception is needed here
if (
tableName ===
'program_financial_service_provider_configuration_property'
) {
sequenceName = 'program_financial_service_pro_id_seq';
}

const maxIdQuery = `SELECT MAX(id) FROM "121-service"."${tableName}"`;

const maxIdResult = await this.dataSource.query(maxIdQuery);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
WITH fsp_data AS (
SELECT fa.id
FROM "121-service".financial_service_provider_question fa
LEFT JOIN "121-service".financial_service_provider f ON f.id = fa."fspId"
WHERE "name" = 'whatsappPhoneNumber' AND f.fsp = 'Intersolve-voucher-whatsapp'
SELECT pra.id
FROM "121-service".program_registration_attribute pra
LEFT JOIN "121-service".program p ON p.id = pra."programId"
LEFT JOIN "121-service".program_financial_service_provider_configuration f ON f."programId" = p.id
WHERE pra."name" = 'whatsappPhoneNumber' AND f."financialServiceProviderName" = 'Intersolve-voucher-whatsapp'
)

UPDATE "121-service".intersolve_voucher iv
SET "whatsappPhoneNumber" = rd."value"
FROM "121-service".imagecode_export_vouchers iev
LEFT JOIN "121-service".registration r ON r.id = iev."registrationId"
LEFT JOIN "121-service".registration_data rd ON r.id = rd."registrationId", fsp_data fd
WHERE iv.id = iev."voucherId" AND rd."fspQuestionId" = fd.id;
LEFT JOIN "121-service".registration_attribute_data rd ON r.id = rd."registrationId", fsp_data fd
WHERE iv.id = iev."voucherId" AND rd."programRegistrationAttributeId" = fd.id;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
update "121-service".registration_data
update "121-service".registration_attribute_data
set "value" = CAST(10000000000 + floor(random() * 90000000000) AS bigint)
WHERE "programQuestionId" IN (SELECT id FROM "121-service".program_question WHERE "name" = 'phoneNumber') OR "fspQuestionId" IN (SELECT id FROM "121-service".financial_service_provider_question WHERE "name" = 'whatsappPhoneNumber');
WHERE "programRegistrationAttributeId" IN (SELECT id FROM "121-service".program_registration_attribute WHERE "name" = 'phoneNumber' OR "name" = 'whatsappPhoneNumber');
;
update "121-service".registration r
set "phoneNumber" = rd."value"
from "121-service".registration_data rd
where rd."registrationId" = r."id" and rd."programQuestionId" in (SELECT id FROM "121-service".program_question WHERE "name" = 'phoneNumber')
from "121-service".registration_attribute_data rd
where rd."registrationId" = r."id" and rd."programRegistrationAttributeId" in (SELECT id FROM "121-service".program_registration_attribute WHERE "name" = 'phoneNumber')
;
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ INSERT INTO "121-service"."transaction"
"customData",
"transactionStep",
"programId",
"financialServiceProviderId",
"registrationId",
amount,
updated,
"userId"
"userId",
"programFinancialServiceProviderConfigurationId"
)
SELECT
created + INTERVAL '1 millisecond' * ROW_NUMBER() OVER (ORDER BY id),
Expand All @@ -21,11 +21,11 @@ SELECT
"customData",
"transactionStep",
"programId",
"financialServiceProviderId",
"registrationId",
amount,
updated,
"userId"
"userId",
"programFinancialServiceProviderConfigurationId"
FROM
"121-service"."transaction"
WHERE
Expand Down
16 changes: 7 additions & 9 deletions services/121-service/src/scripts/sql/mock-registration-data.sql
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
INSERT
INTO
"121-service"."registration_data" (
"121-service"."registration_attribute_data" (
SELECT
id + (
SELECT
max(id)
FROM
"121-service"."registration_data") AS id,
"121-service"."registration_attribute_data") AS id,
created,
updated,
"registrationId" + (
SELECT
max("registrationId")
FROM
"121-service"."registration_data") AS "registrationId",
"programQuestionId",
"fspQuestionId",
"programCustomAttributeId",
value,
updated
"121-service"."registration_attribute_data") AS "registrationId",
"programRegistrationAttributeId",
value
FROM
"121-service"."registration_data");
"121-service"."registration_attribute_data");
4 changes: 2 additions & 2 deletions services/121-service/src/scripts/sql/mock-registrations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ INSERT
"paymentAmountMultiplier",
"programId",
"userId",
"programFinancialServiceProviderConfigurationId",
updated,
"registrationProgramId" + (
SELECT
Expand All @@ -32,6 +31,7 @@ INSERT
ELSE 'zeeland.goes'
END
ELSE scope
END
END,
"programFinancialServiceProviderConfigurationId"
FROM
"121-service".registration);
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ INSERT INTO "121-service"."transaction" (
"customData",
"transactionStep",
"programId",
"financialServiceProviderId",
"registrationId",
amount,
updated,
"userId"
"userId",
"programFinancialServiceProviderConfigurationId"
)
SELECT
created + INTERVAL '1 millisecond' * ROW_NUMBER() OVER (ORDER BY id),
Expand All @@ -20,11 +20,11 @@ SELECT
"customData",
"transactionStep",
"programId",
"financialServiceProviderId",
"registrationId" + (SELECT max("registrationId") FROM "121-service"."transaction"),
amount,
updated,
"userId"
"userId",
"programFinancialServiceProviderConfigurationId"
FROM
"121-service"."transaction"
WHERE
Expand Down
4 changes: 2 additions & 2 deletions services/121-service/src/scripts/sql/mock-visa-customers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ INSERT
,'mock-holderId'
,r.id
from "121-service".registration r
left join "121-service".financial_service_provider f on r."fspId" = f.id
where f.fsp = 'Intersolve-visa');
left join "121-service".program_financial_service_provider_configuration f on r."programFinancialServiceProviderConfigurationId" = f.id
where f."financialServiceProviderName" = 'Intersolve-visa');
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export const registrationAHWhatsapp = {
fullName: 'Juan Garcia',
scope: 'utrecht.houten',
[DefaultRegistrationDataAttributeNames.phoneNumber]: '14155238888',
fspName: FinancialServiceProviders.intersolveVoucherWhatsapp,
programFinancialServiceProviderConfigurationName:
FinancialServiceProviders.intersolveVoucherWhatsapp,
[DefaultRegistrationDataAttributeNames.whatsappPhoneNumber]: '14155238888',
namePartnerOrganization: 'Help Elkaar',
};

0 comments on commit 62a6df1

Please sign in to comment.