Skip to content

Commit 950b475

Browse files
Merge pull request #206 from GeneralMagicio/add-vesting-table
added vesting table
2 parents 2c56938 + 382273f commit 950b475

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { MigrationInterface, QueryRunner } from 'typeorm';
2+
3+
export class AddVestingTableMigration1746211907434
4+
implements MigrationInterface
5+
{
6+
name = 'Migration1746211907434';
7+
8+
public async up(queryRunner: QueryRunner): Promise<void> {
9+
await queryRunner.query(
10+
`CREATE TABLE "vesting_data" ("id" SERIAL NOT NULL, "status" text NOT NULL DEFAULT 'pending', "walletAddress" character varying, "paymentToken" character varying NOT NULL, "amount" bigint NOT NULL, "rewardStreamStart" TIMESTAMP, "cliff" double precision, "rewardStreamEnd" TIMESTAMP, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "projectId" integer, "userId" integer, CONSTRAINT "PK_c8abbf61fa05ae0eec4048b6408" PRIMARY KEY ("id"))`,
11+
);
12+
await queryRunner.query(
13+
`CREATE INDEX "IDX_2826daca8f0317c5e209df4de5" ON "vesting_data" ("projectId") `,
14+
);
15+
await queryRunner.query(
16+
`CREATE INDEX "IDX_b81d2052f429a1bce90dc68e2e" ON "vesting_data" ("userId") `,
17+
);
18+
await queryRunner.query(
19+
`ALTER TABLE "vesting_data" ADD CONSTRAINT "FK_2826daca8f0317c5e209df4de55" FOREIGN KEY ("projectId") REFERENCES "project"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
20+
);
21+
await queryRunner.query(
22+
`ALTER TABLE "vesting_data" ADD CONSTRAINT "FK_b81d2052f429a1bce90dc68e2ee" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
23+
);
24+
}
25+
26+
public async down(queryRunner: QueryRunner): Promise<void> {
27+
await queryRunner.query(
28+
`ALTER TABLE "vesting_data" DROP CONSTRAINT "FK_b81d2052f429a1bce90dc68e2ee"`,
29+
);
30+
await queryRunner.query(
31+
`ALTER TABLE "vesting_data" DROP CONSTRAINT "FK_2826daca8f0317c5e209df4de55"`,
32+
);
33+
await queryRunner.query(
34+
`DROP INDEX "public"."IDX_b81d2052f429a1bce90dc68e2e"`,
35+
);
36+
await queryRunner.query(
37+
`DROP INDEX "public"."IDX_2826daca8f0317c5e209df4de5"`,
38+
);
39+
await queryRunner.query(`DROP TABLE "vesting_data"`);
40+
}
41+
}

src/entities/entities.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { AnkrState } from './ankrState';
3939
import { SwapTransaction } from './swapTransaction';
4040
import { QaccPointsHistory } from './qaccPointsHistory';
4141
import { UserRankMaterializedView } from './userRanksMaterialized';
42+
import { VestingData } from './vestingData';
4243

4344
export const getEntities = (): DataSourceOptions['entities'] => {
4445
return [
@@ -91,5 +92,6 @@ export const getEntities = (): DataSourceOptions['entities'] => {
9192
AnkrState,
9293
SwapTransaction,
9394
UserRankMaterializedView,
95+
VestingData,
9496
];
9597
};

src/entities/vestingData.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { Field, ID, ObjectType } from 'type-graphql';
2+
import {
3+
BaseEntity,
4+
Column,
5+
CreateDateColumn,
6+
Entity,
7+
Index,
8+
ManyToOne,
9+
PrimaryGeneratedColumn,
10+
} from 'typeorm';
11+
import { User } from './user';
12+
import { Project } from './project';
13+
14+
export const VESTING_STATUS = {
15+
PENDING: 'pending',
16+
FINAL: 'FINAL',
17+
};
18+
19+
@ObjectType()
20+
@Entity('vesting_data')
21+
export class VestingData extends BaseEntity {
22+
@Field(_type => ID)
23+
@PrimaryGeneratedColumn()
24+
readonly id: number;
25+
26+
@Index()
27+
@Field(_type => Project)
28+
@ManyToOne(_type => Project, { eager: true })
29+
project: Project;
30+
31+
@Field()
32+
@Column('text', { default: VESTING_STATUS.PENDING })
33+
status: string;
34+
35+
@Index()
36+
@Field(_type => User, { nullable: true })
37+
@ManyToOne(() => User, { eager: true, onDelete: 'CASCADE' })
38+
user: User;
39+
40+
@Field(_type => String, { nullable: true })
41+
@Column({ nullable: true })
42+
walletAddress?: string;
43+
44+
@Field()
45+
@Column()
46+
paymentToken: string;
47+
48+
@Field()
49+
@Column({ type: 'bigint' })
50+
amount: string;
51+
52+
@Field({ nullable: true })
53+
@Column({ nullable: true })
54+
rewardStreamStart?: Date;
55+
56+
@Field({ nullable: true })
57+
@Column({ type: 'float', nullable: true })
58+
cliff?: number;
59+
60+
@Field({ nullable: true })
61+
@Column({ nullable: true })
62+
rewardStreamEnd?: Date;
63+
64+
@CreateDateColumn()
65+
createdAt: Date;
66+
}

0 commit comments

Comments
 (0)