All files / src/Projection/migrations 1682519108369-fk-pool-registration.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 { PoolRegistrationEntity } from '@cardano-sdk/projection-typeorm';
 
export class FkPoolRegistrationMigration1682519108369 implements MigrationInterface {
  static entity = PoolRegistrationEntity;
 
  async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      'ALTER TABLE "pool_registration" ADD CONSTRAINT "FK_pool_registration_stake_pool_id" FOREIGN KEY ("stake_pool_id") REFERENCES "stake_pool"("id") ON DELETE CASCADE ON UPDATE NO ACTION'
    );
    await queryRunner.query(
      'ALTER TABLE "stake_pool" ADD CONSTRAINT "FK_stake_pool_last_registration_id" FOREIGN KEY ("last_registration_id") REFERENCES "pool_registration"("id") ON DELETE SET NULL ON UPDATE NO ACTION'
    );
  }
 
  async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query('ALTER TABLE "stake_pool" DROP CONSTRAINT "FK_stake_pool_last_registration_id"');
    await queryRunner.query('ALTER TABLE "pool_registration" DROP CONSTRAINT "FK_pool_registration_stake_pool_id"');
  }
}