diff --git a/api/src/migrations/1667497567675-ImpactMaterializedViewUniqueIndex.ts b/api/src/migrations/1667497567675-ImpactMaterializedViewUniqueIndex.ts new file mode 100644 index 0000000000..ecc79a7d1b --- /dev/null +++ b/api/src/migrations/1667497567675-ImpactMaterializedViewUniqueIndex.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class ImpactMaterializedViewUniqueIndex1667497567675 + implements MigrationInterface +{ + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + DROP INDEX IF EXISTS idx_georegion_h3data_indexed; + CREATE UNIQUE INDEX idx_georegion_h3data_indexed ON impact_materialized_view ("geoRegionId", "h3DataId", "h3index") INCLUDE ("value"); + `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + DROP INDEX IF EXISTS idx_georegion_h3data_indexed; + `); + } +} diff --git a/api/src/modules/indicator-records/indicator-record.entity.ts b/api/src/modules/indicator-records/indicator-record.entity.ts index 46f96da14b..15d140821c 100644 --- a/api/src/modules/indicator-records/indicator-record.entity.ts +++ b/api/src/modules/indicator-records/indicator-record.entity.ts @@ -108,7 +108,7 @@ export class IndicatorRecord extends TimestampedBaseEntity { static updateImpactView(): Promise { return getManager().query( - `REFRESH MATERIALIZED VIEW ${IMPACT_VIEW_NAME} WITH DATA`, + `REFRESH MATERIALIZED VIEW CONCURRENTLY ${IMPACT_VIEW_NAME} WITH DATA`, ); } }