This commit is contained in:
Bright 2025-02-13 17:53:34 +07:00
parent dbce13d107
commit 88af7fcbb0
2 changed files with 47 additions and 24 deletions

View file

@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateView1739443292907 implements MigrationInterface {
name = 'UpdateView1739443292907'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE VIEW \`view_profile_evaluation\` AS SELECT MAX(\`rootId\`) AS rootId,
MAX(\`root\`) AS root,\`degreeLevel\`,
COUNT(*) AS numberOfRecords,
COUNT(DISTINCT \`scholarshipType\`) AS numberOfScholarshipTypes,
SUM(\`budgetApprove\`) AS totalBudgetApprove
FROM \`developmentScholarship\`
GROUP BY \`rootId\`,\`degreeLevel\`
`);
await queryRunner.query(`INSERT INTO \`bma_ehr_development_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_development_demo","VIEW","view_profile_evaluation","SELECT MAX(`rootId`) AS rootId, \n MAX(`root`) AS root,`degreeLevel`,\n COUNT(*) AS numberOfRecords, \n COUNT(DISTINCT `scholarshipType`) AS numberOfScholarshipTypes,\n SUM(`budgetApprove`) AS totalBudgetApprove\n FROM `developmentScholarship`\n GROUP BY `rootId`,`degreeLevel`"]);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DELETE FROM \`bma_ehr_development_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_profile_evaluation","bma_ehr_development_demo"]);
await queryRunner.query(`DROP VIEW \`view_profile_evaluation\``);
}
}