Skip to content

Commit

Permalink
feature/add-governance-action-worker-job: fixed governance migration
Browse files Browse the repository at this point in the history
  • Loading branch information
BEdev24 committed Jun 24, 2024
1 parent fd62735 commit 4bc3d6d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions backend/migrations/1719240004920-governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ export class Governance1719240004920 implements MigrationInterface {
name = 'Governance1719240004920';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "reasonings" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "gov_action_proposal_id" bigint, CONSTRAINT "PK_ff38dc62e0ad413f4bcb92e8d40" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE TABLE "gov_action_proposals" ("created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP DEFAULT now(), "id" bigint NOT NULL, "tx_hash" character varying NOT NULL, "voting_anchor_id" bigint NOT NULL, "title" character varying(80), "abstract" character varying(2500), "gov_metadata_url" character varying NOT NULL, "status" character varying NOT NULL, "gov_action_type" character varying NOT NULL, "end_time" TIMESTAMP NOT NULL, CONSTRAINT "PK_761fb8cdf90aec7d72873e63e31" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE TABLE "votes" ("created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP DEFAULT now(), "id" bigint NOT NULL, "user_id" uuid NOT NULL, "hot_address" character varying NOT NULL, "vote" character varying NOT NULL, "title" character varying, "comment" character varying, "submit_time" TIMESTAMP NOT NULL, "gov_action_proposal_id" bigint, CONSTRAINT "PK_f3d9fd4a0af865152c3f59db8ff" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`ALTER TABLE "reasonings" ADD CONSTRAINT "FK_4aa195e062f6f7c0853376a2444" FOREIGN KEY ("gov_action_proposal_id") REFERENCES "gov_action_proposals"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
Expand All @@ -22,6 +28,8 @@ export class Governance1719240004920 implements MigrationInterface {
await queryRunner.query(
`ALTER TABLE "reasonings" DROP CONSTRAINT "FK_4aa195e062f6f7c0853376a2444"`,
);
await queryRunner.query(`DROP TABLE "votes"`);
await queryRunner.query(`DROP TABLE "gov_action_proposals"`);
await queryRunner.query(`DROP TABLE "reasonings"`);
}
}
3 changes: 3 additions & 0 deletions backend/src/governance/entities/gov-action-proposal.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export class GovActionProposal extends CommonEntity {
@PrimaryGeneratedColumn()
id: number;

@Column({ name: 'tx_hash', type: 'varchar' })
txHash: string;

@Column({
name: 'voting_anchor_id',
type: 'bigint',
Expand Down
18 changes: 18 additions & 0 deletions backend/src/governance/entities/reasoning.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { GovActionProposal } from './gov-action-proposal.entity';

@Entity('reasonings')
export class Reasoning {
@PrimaryGeneratedColumn('uuid')
id: string;

@ManyToOne(
() => GovActionProposal,
(govActionProposal) => govActionProposal.txHash,
{
eager: true,
},
)
@JoinColumn({ name: 'gov_action_proposal_id' })
govActionProposal: GovActionProposal;
}

0 comments on commit 4bc3d6d

Please sign in to comment.