All files / src/Projection/migrations 1685011799580-stake-pool-metrics-table.ts

42.85% Statements 3/7
100% Branches 0/0
0% Functions 0/2
42.85% Lines 3/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 2340x     40x 40x                                    
import { CurrentPoolMetricsEntity } from '@cardano-sdk/projection-typeorm';
import { MigrationInterface, QueryRunner } from 'typeorm';
 
export class PoolMetricsMigrations1685011799580 implements MigrationInterface {
  static entity = CurrentPoolMetricsEntity;
 
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      'CREATE TABLE "current_pool_metrics" ("stake_pool_id" character(56) NOT NULL, "slot" integer NOT NULL, "minted_blocks" integer NOT NULL, "live_delegators" integer NOT NULL, "active_stake" bigint NOT NULL, "live_stake" bigint NOT NULL, "live_pledge" bigint NOT NULL, "live_saturation" numeric NOT NULL, "active_size" numeric NOT NULL, "live_size" numeric NOT NULL, "apy" numeric NOT NULL, CONSTRAINT "PK_current_pool_metrics_stake_pool_id" PRIMARY KEY ("stake_pool_id"))'
    );
    await queryRunner.query(
      'ALTER TABLE "current_pool_metrics" ADD CONSTRAINT "FK_current_pool_metrics_stake_pool_id" FOREIGN KEY ("stake_pool_id") REFERENCES "stake_pool"("id") ON DELETE CASCADE ON UPDATE NO ACTION'
    );
  }
 
  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      'ALTER TABLE "current_pool_metrics" DROP CONSTRAINT "FK_current_pool_metrics_stake_pool_id"'
    );
    await queryRunner.query('DROP TABLE "current_pool_metrics"');
  }
}