All files / src/Projection/migrations 1698175956871-pool-rewards-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  40x   40x 40x                                
import { MigrationInterface, QueryRunner } from 'typeorm';
import { PoolRewardsEntity } from '@cardano-sdk/projection-typeorm';
 
export class PoolRewardsTableMigrations1698175956871 implements MigrationInterface {
  static entity = PoolRewardsEntity;
 
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      'CREATE TABLE "pool_rewards" ("id" SERIAL NOT NULL, "stake_pool_id" character(56) NOT NULL, "epoch_length" integer NOT NULL, "epoch_no" integer NOT NULL, "delegators" integer NOT NULL, "pledge" bigint NOT NULL, "active_stake" numeric(20,0) NOT NULL, "member_active_stake" numeric(20,0) NOT NULL, "leader_rewards" numeric(20,0) NOT NULL, "member_rewards" numeric(20,0) NOT NULL, "rewards" numeric(20,0) NOT NULL, "version" integer NOT NULL, CONSTRAINT "UQ_pool_rewards_epoch_no_stake_pool_id}" UNIQUE ("epoch_no", "stake_pool_id"), CONSTRAINT "PK_pool_rewards_id" PRIMARY KEY ("id"))'
    );
    await queryRunner.query(
      'ALTER TABLE "pool_rewards" ADD CONSTRAINT "FK_pool_rewards_stake_pool_id" FOREIGN KEY ("stake_pool_id") REFERENCES "stake_pool"("id") ON DELETE NO ACTION ON UPDATE NO ACTION'
    );
  }
 
  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query('ALTER TABLE "pool_rewards" DROP CONSTRAINT "FK_pool_rewards_stake_pool_id"');
    await queryRunner.query('DROP TABLE "pool_rewards"');
  }
}