update viewProfileEva
This commit is contained in:
parent
d4f440295c
commit
e9120f63ba
1 changed files with 35 additions and 0 deletions
35
src/migration/1739153948936-update_viewProfileEvaluation.ts
Normal file
35
src/migration/1739153948936-update_viewProfileEvaluation.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateViewProfileEvaluation1739153948936 implements MigrationInterface {
|
||||
name = 'UpdateViewProfileEvaluation1739153948936'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_profile_evaluation","bma_ehr_organization_demo"]);
|
||||
await queryRunner.query(`DROP VIEW \`view_profile_evaluation\``);
|
||||
await queryRunner.query(`CREATE VIEW \`view_profile_evaluation\` AS SELECT
|
||||
\`profileId\`,\`period\`,\`year\`,\`posMaster\`.\`orgRootId\`,\`posMaster\`.\`orgChild1Id\`,\`posMaster\`.\`orgChild2Id\`,\`posMaster\`.\`orgChild3Id\`,\`posMaster\`.\`orgChild4Id\`, COUNT(*) AS recordCount, SUM(pointSum) AS totalPointSum, SUM(pointSum) / COUNT(*) AS result
|
||||
FROM\`profileAssessment\`
|
||||
LEFT JOIN \`profile\` ON \`profileAssessment\`.\`profileId\` = \`profile\`.\`id\`
|
||||
LEFT JOIN \`posMaster\` ON \`profile\`.\`id\` = \`posMaster\`.\`current_holderId\`
|
||||
LEFT JOIN \`orgRevision\` ON \`posMaster\`.\`orgRevisionId\` = \`orgRevision\`.\`id\`
|
||||
WHERE \`period\` Is not null
|
||||
AND \`orgRevision\`.\`orgRevisionIsCurrent\` = true
|
||||
GROUP BY\`profileId\`,\`period\`,\`year\`,\`orgRootId\`,\`orgChild1Id\`,\`orgChild2Id\`,\`orgChild3Id\`,\`orgChild4Id\`
|
||||
ORDER BY\`year\` desc ,\`period\` asc
|
||||
`);
|
||||
await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_profile_evaluation","SELECT \n `profileId`,`period`,`year`,`posMaster`.`orgRootId`,`posMaster`.`orgChild1Id`,`posMaster`.`orgChild2Id`,`posMaster`.`orgChild3Id`,`posMaster`.`orgChild4Id`, COUNT(*) AS recordCount, SUM(pointSum) AS totalPointSum, SUM(pointSum) / COUNT(*) AS result\n FROM`profileAssessment` \n LEFT JOIN `profile` ON `profileAssessment`.`profileId` = `profile`.`id`\n LEFT JOIN `posMaster` ON `profile`.`id` = `posMaster`.`current_holderId`\n LEFT JOIN `orgRevision` ON `posMaster`.`orgRevisionId` = `orgRevision`.`id`\n WHERE `period` Is not null\n AND `orgRevision`.`orgRevisionIsCurrent` = true\n GROUP BY`profileId`,`period`,`year`,`orgRootId`,`orgChild1Id`,`orgChild2Id`,`orgChild3Id`,`orgChild4Id`\n ORDER BY`year` desc ,`period` asc"]);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_profile_evaluation","bma_ehr_organization_demo"]);
|
||||
await queryRunner.query(`DROP VIEW \`view_profile_evaluation\``);
|
||||
await queryRunner.query(`CREATE VIEW \`view_profile_evaluation\` AS SELECT
|
||||
\`profileId\`, \`period\`, \`year\`, COUNT(*) AS recordCount, SUM(pointSum) AS totalPointSum, SUM(pointSum) / COUNT(*) AS result
|
||||
FROM \`profileAssessment\`
|
||||
WHERE \`period\` Is not null
|
||||
GROUP BY \`profileId\`, \`period\`, \`year\`
|
||||
ORDER BY \`year\` desc , \`period\` asc`);
|
||||
await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_profile_evaluation","SELECT \n `profileId`, `period`, `year`, COUNT(*) AS recordCount, SUM(pointSum) AS totalPointSum, SUM(pointSum) / COUNT(*) AS result\n FROM `profileAssessment` \n WHERE `period` Is not null\n GROUP BY `profileId`, `period`, `year`\n ORDER BY `year` desc , `period` asc"]);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue