Skip to content

Commit

Permalink
feat: add stake pool metadata entity relation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivaylo Andonov committed May 25, 2023
1 parent 82bf157 commit d2aa327
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
Expand Up @@ -84,7 +84,7 @@ const entityInterDependencies: Partial<Record<EntityName, EntityName[]>> = {
output: ['block'],
poolRegistration: ['block'],
poolRetirement: ['block'],
stakePool: ['block'],
stakePool: ['block', 'poolRegistration', 'poolRetirement', 'poolMetadata'],
tokens: ['asset']
};

Expand Down
Expand Up @@ -26,6 +26,6 @@ export class PoolMetadataEntity {
@ManyToOne(() => StakePoolEntity)
stakePool?: StakePoolEntity;
@JoinColumn()
@OneToOne(() => PoolRegistrationEntity, DeleteCascadeRelationOptions)
@OneToOne(() => PoolRegistrationEntity, (poolUpdate) => poolUpdate.metadata, DeleteCascadeRelationOptions)
poolUpdate?: PoolRegistrationEntity;
}
Expand Up @@ -2,7 +2,8 @@
import { BigIntColumnOptions, DeleteCascadeRelationOptions } from './util';
import { BlockEntity } from './Block.entity';
import { Cardano } from '@cardano-sdk/core';
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from 'typeorm';
import { Column, Entity, JoinColumn, ManyToOne, OneToOne, PrimaryColumn } from 'typeorm';
import { PoolMetadataEntity } from './PoolMetadata.entity';
import { StakePoolEntity } from './StakePool.entity';

@Entity()
Expand Down Expand Up @@ -39,6 +40,8 @@ export class PoolRegistrationEntity {
@JoinColumn()
@ManyToOne(() => StakePoolEntity, (stakePool) => stakePool.registrations, DeleteCascadeRelationOptions)
stakePool?: StakePoolEntity;
@OneToOne(() => PoolMetadataEntity, (metadata) => metadata.poolUpdate)
metadata?: PoolMetadataEntity | null;
@ManyToOne(() => BlockEntity, DeleteCascadeRelationOptions)
@JoinColumn()
block?: BlockEntity;
Expand Down
@@ -1,6 +1,7 @@
import {
BlockDataEntity,
BlockEntity,
PoolMetadataEntity,
PoolRegistrationEntity,
PoolRetirementEntity,
StakePoolEntity,
Expand Down Expand Up @@ -56,7 +57,14 @@ describe('storeStakePools', () => {

beforeEach(async () => {
dataSource = await initializeDataSource({
entities: [BlockDataEntity, BlockEntity, StakePoolEntity, PoolRegistrationEntity, PoolRetirementEntity]
entities: [
BlockDataEntity,
BlockEntity,
StakePoolEntity,
PoolRegistrationEntity,
PoolRetirementEntity,
PoolMetadataEntity
]
});
queryRunner = dataSource.createQueryRunner();
poolsRepo = queryRunner.manager.getRepository(StakePoolEntity);
Expand Down

0 comments on commit d2aa327

Please sign in to comment.