Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/migrations/1712000000000-CreateWebhookSubscriptionsTable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class CreateWebhookSubscriptionsTable1712000000000
implements MigrationInterface
{
name = "CreateWebhookSubscriptionsTable1712000000000";

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TABLE "webhook_subscriptions" (
"id" uuid NOT NULL DEFAULT gen_random_uuid(),
"user_id" uuid NOT NULL,
"url" character varying(255) NOT NULL,
"secret" character varying(64) NOT NULL,
"event_types" jsonb NOT NULL,
"active" boolean NOT NULL DEFAULT true,
"created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
"updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
CONSTRAINT "PK_webhook_subscriptions" PRIMARY KEY ("id")
);
`);

await queryRunner.query(`
CREATE INDEX "idx_webhook_subscriptions_user_id"
ON "webhook_subscriptions" ("user_id");
`);

await queryRunner.query(`
ALTER TABLE "webhook_subscriptions"
ADD CONSTRAINT "FK_webhook_subscriptions_user"
FOREIGN KEY ("user_id") REFERENCES "users"("id")
ON DELETE CASCADE;
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE "webhook_subscriptions"
DROP CONSTRAINT "FK_webhook_subscriptions_user";
`);

await queryRunner.query(`
DROP INDEX "public"."idx_webhook_subscriptions_user_id";
`);

await queryRunner.query(`DROP TABLE "webhook_subscriptions"`);
}
}
36 changes: 36 additions & 0 deletions src/migrations/1713000000000-CreateSorobanEventLogsTable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class CreateSorobanEventLogsTable1713000000000
implements MigrationInterface
{
name = "CreateSorobanEventLogsTable1713000000000";

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TABLE "soroban_event_logs" (
"id" uuid NOT NULL DEFAULT gen_random_uuid(),
"contract_id" character varying(56) NOT NULL,
"ledger_sequence" bigint NOT NULL,
"topic" character varying(64) NOT NULL,
"tx_hash" character varying(64) NOT NULL,
"payload" jsonb,
"processed" boolean NOT NULL DEFAULT false,
"created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
CONSTRAINT "PK_soroban_event_logs" PRIMARY KEY ("id")
);
`);

await queryRunner.query(`
CREATE INDEX "idx_soroban_event_logs_processed"
ON "soroban_event_logs" ("processed");
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DROP INDEX "public"."idx_soroban_event_logs_processed";
`);

await queryRunner.query(`DROP TABLE "soroban_event_logs"`);
}
}
20 changes: 20 additions & 0 deletions src/migrations/1714000000000-AddSorobanEventLogsIndex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class AddSorobanEventLogsIndex1714000000000
implements MigrationInterface
{
name = "AddSorobanEventLogsIndex1714000000000";

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE INDEX "IDX_SOROBAN_EVENTS_CONTRACT_LEDGER"
ON "soroban_event_logs" ("contract_id", "ledger_sequence" DESC);
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DROP INDEX "public"."IDX_SOROBAN_EVENTS_CONTRACT_LEDGER";
`);
}
}
35 changes: 35 additions & 0 deletions src/models/SorobanEventLog.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
Column,
CreateDateColumn,
Entity,
Index,
PrimaryGeneratedColumn,
} from "typeorm";

@Entity("soroban_event_logs")
export class SorobanEventLog {
@PrimaryGeneratedColumn("uuid")
id!: string;

@Column({ name: "contract_id", type: "varchar", length: 56 })
contractId!: string;

@Column({ name: "ledger_sequence", type: "bigint" })
ledgerSequence!: string;

@Column({ type: "varchar", length: 64 })
topic!: string;

@Column({ name: "tx_hash", type: "varchar", length: 64 })
txHash!: string;

@Column({ type: "jsonb", nullable: true })
payload!: Record<string, unknown> | null;

@Column({ type: "boolean", default: false })
@Index("idx_soroban_event_logs_processed")
processed!: boolean;

@CreateDateColumn({ name: "created_at", type: "timestamptz" })
createdAt!: Date;
}
43 changes: 43 additions & 0 deletions src/models/WebhookSubscription.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
Column,
CreateDateColumn,
Entity,
Index,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from "typeorm";
import type { User } from "./User.model";

@Entity("webhook_subscriptions")
export class WebhookSubscription {
@PrimaryGeneratedColumn("uuid")
id!: string;

@Column({ name: "user_id", type: "uuid" })
@Index("idx_webhook_subscriptions_user_id")
userId!: string;

@Column({ type: "varchar", length: 255 })
url!: string;

@Column({ type: "varchar", length: 64 })
secret!: string;

@Column({ name: "event_types", type: "jsonb" })
eventTypes!: string[];

@Column({ type: "boolean", default: true })
active!: boolean;

@CreateDateColumn({ name: "created_at", type: "timestamptz" })
createdAt!: Date;

@UpdateDateColumn({ name: "updated_at", type: "timestamptz" })
updatedAt!: Date;

@ManyToOne("User", { onDelete: "CASCADE" })
@JoinColumn({ name: "user_id" })
user!: User;
}
Loading