Skip to content

Commit 68d09dc

Browse files
authored
Merge pull request #197 from silifatzoffun74-art/feat/issues-168-167-166
feat: add TypeORM migrations for webhook_subscriptions, soroban_event_logs and index
2 parents e5c25e5 + 26f485a commit 68d09dc

5 files changed

Lines changed: 182 additions & 0 deletions
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm";
2+
3+
export class CreateWebhookSubscriptionsTable1712000000000
4+
implements MigrationInterface
5+
{
6+
name = "CreateWebhookSubscriptionsTable1712000000000";
7+
8+
public async up(queryRunner: QueryRunner): Promise<void> {
9+
await queryRunner.query(`
10+
CREATE TABLE "webhook_subscriptions" (
11+
"id" uuid NOT NULL DEFAULT gen_random_uuid(),
12+
"user_id" uuid NOT NULL,
13+
"url" character varying(255) NOT NULL,
14+
"secret" character varying(64) NOT NULL,
15+
"event_types" jsonb NOT NULL,
16+
"active" boolean NOT NULL DEFAULT true,
17+
"created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
18+
"updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
19+
CONSTRAINT "PK_webhook_subscriptions" PRIMARY KEY ("id")
20+
);
21+
`);
22+
23+
await queryRunner.query(`
24+
CREATE INDEX "idx_webhook_subscriptions_user_id"
25+
ON "webhook_subscriptions" ("user_id");
26+
`);
27+
28+
await queryRunner.query(`
29+
ALTER TABLE "webhook_subscriptions"
30+
ADD CONSTRAINT "FK_webhook_subscriptions_user"
31+
FOREIGN KEY ("user_id") REFERENCES "users"("id")
32+
ON DELETE CASCADE;
33+
`);
34+
}
35+
36+
public async down(queryRunner: QueryRunner): Promise<void> {
37+
await queryRunner.query(`
38+
ALTER TABLE "webhook_subscriptions"
39+
DROP CONSTRAINT "FK_webhook_subscriptions_user";
40+
`);
41+
42+
await queryRunner.query(`
43+
DROP INDEX "public"."idx_webhook_subscriptions_user_id";
44+
`);
45+
46+
await queryRunner.query(`DROP TABLE "webhook_subscriptions"`);
47+
}
48+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm";
2+
3+
export class CreateSorobanEventLogsTable1713000000000
4+
implements MigrationInterface
5+
{
6+
name = "CreateSorobanEventLogsTable1713000000000";
7+
8+
public async up(queryRunner: QueryRunner): Promise<void> {
9+
await queryRunner.query(`
10+
CREATE TABLE "soroban_event_logs" (
11+
"id" uuid NOT NULL DEFAULT gen_random_uuid(),
12+
"contract_id" character varying(56) NOT NULL,
13+
"ledger_sequence" bigint NOT NULL,
14+
"topic" character varying(64) NOT NULL,
15+
"tx_hash" character varying(64) NOT NULL,
16+
"payload" jsonb,
17+
"processed" boolean NOT NULL DEFAULT false,
18+
"created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
19+
CONSTRAINT "PK_soroban_event_logs" PRIMARY KEY ("id")
20+
);
21+
`);
22+
23+
await queryRunner.query(`
24+
CREATE INDEX "idx_soroban_event_logs_processed"
25+
ON "soroban_event_logs" ("processed");
26+
`);
27+
}
28+
29+
public async down(queryRunner: QueryRunner): Promise<void> {
30+
await queryRunner.query(`
31+
DROP INDEX "public"."idx_soroban_event_logs_processed";
32+
`);
33+
34+
await queryRunner.query(`DROP TABLE "soroban_event_logs"`);
35+
}
36+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm";
2+
3+
export class AddSorobanEventLogsIndex1714000000000
4+
implements MigrationInterface
5+
{
6+
name = "AddSorobanEventLogsIndex1714000000000";
7+
8+
public async up(queryRunner: QueryRunner): Promise<void> {
9+
await queryRunner.query(`
10+
CREATE INDEX "IDX_SOROBAN_EVENTS_CONTRACT_LEDGER"
11+
ON "soroban_event_logs" ("contract_id", "ledger_sequence" DESC);
12+
`);
13+
}
14+
15+
public async down(queryRunner: QueryRunner): Promise<void> {
16+
await queryRunner.query(`
17+
DROP INDEX "public"."IDX_SOROBAN_EVENTS_CONTRACT_LEDGER";
18+
`);
19+
}
20+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {
2+
Column,
3+
CreateDateColumn,
4+
Entity,
5+
Index,
6+
PrimaryGeneratedColumn,
7+
} from "typeorm";
8+
9+
@Entity("soroban_event_logs")
10+
export class SorobanEventLog {
11+
@PrimaryGeneratedColumn("uuid")
12+
id!: string;
13+
14+
@Column({ name: "contract_id", type: "varchar", length: 56 })
15+
contractId!: string;
16+
17+
@Column({ name: "ledger_sequence", type: "bigint" })
18+
ledgerSequence!: string;
19+
20+
@Column({ type: "varchar", length: 64 })
21+
topic!: string;
22+
23+
@Column({ name: "tx_hash", type: "varchar", length: 64 })
24+
txHash!: string;
25+
26+
@Column({ type: "jsonb", nullable: true })
27+
payload!: Record<string, unknown> | null;
28+
29+
@Column({ type: "boolean", default: false })
30+
@Index("idx_soroban_event_logs_processed")
31+
processed!: boolean;
32+
33+
@CreateDateColumn({ name: "created_at", type: "timestamptz" })
34+
createdAt!: Date;
35+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {
2+
Column,
3+
CreateDateColumn,
4+
Entity,
5+
Index,
6+
JoinColumn,
7+
ManyToOne,
8+
PrimaryGeneratedColumn,
9+
UpdateDateColumn,
10+
} from "typeorm";
11+
import type { User } from "./User.model";
12+
13+
@Entity("webhook_subscriptions")
14+
export class WebhookSubscription {
15+
@PrimaryGeneratedColumn("uuid")
16+
id!: string;
17+
18+
@Column({ name: "user_id", type: "uuid" })
19+
@Index("idx_webhook_subscriptions_user_id")
20+
userId!: string;
21+
22+
@Column({ type: "varchar", length: 255 })
23+
url!: string;
24+
25+
@Column({ type: "varchar", length: 64 })
26+
secret!: string;
27+
28+
@Column({ name: "event_types", type: "jsonb" })
29+
eventTypes!: string[];
30+
31+
@Column({ type: "boolean", default: true })
32+
active!: boolean;
33+
34+
@CreateDateColumn({ name: "created_at", type: "timestamptz" })
35+
createdAt!: Date;
36+
37+
@UpdateDateColumn({ name: "updated_at", type: "timestamptz" })
38+
updatedAt!: Date;
39+
40+
@ManyToOne("User", { onDelete: "CASCADE" })
41+
@JoinColumn({ name: "user_id" })
42+
user!: User;
43+
}

0 commit comments

Comments
 (0)