Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create initial migration #57

Closed
wants to merge 1 commit into from
Closed
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
94 changes: 94 additions & 0 deletions prisma/migrations/20230817000541_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
-- CreateTable
CREATE TABLE "Event" (
"observedTimestamp" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"blockNumber" INTEGER NOT NULL,
"logIndex" INTEGER NOT NULL,
"blockHash" BLOB NOT NULL,
"txHash" BLOB NOT NULL,
"topic1" BLOB,
"topic2" BLOB,
"topic3" BLOB,
"data" BLOB NOT NULL,
"emittedTimestamp" DATETIME,
"lockedTimestamp" DATETIME,
"abiHash" BLOB NOT NULL,
"sourceAddress" BLOB NOT NULL,

PRIMARY KEY ("blockNumber", "logIndex"),
CONSTRAINT "Event_sourceAddress_abiHash_fkey" FOREIGN KEY ("sourceAddress", "abiHash") REFERENCES "EventSource" ("address", "abiHash") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Event_abiHash_fkey" FOREIGN KEY ("abiHash") REFERENCES "EventAbi" ("hash") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "ObservedLog" (
"blockNumber" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT
);

-- CreateTable
CREATE TABLE "BlockProcessError" (
"blockNumber" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT
);

-- CreateTable
CREATE TABLE "FailedUrl" (
"blockNumber" INTEGER NOT NULL,
"logIndex" INTEGER NOT NULL,
"url" TEXT NOT NULL,

PRIMARY KEY ("blockNumber", "logIndex", "url"),
CONSTRAINT "FailedUrl_blockNumber_logIndex_fkey" FOREIGN KEY ("blockNumber", "logIndex") REFERENCES "Event" ("blockNumber", "logIndex") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "EventAbi" (
"hash" BLOB NOT NULL PRIMARY KEY,
"json" TEXT NOT NULL
);

-- CreateTable
CREATE TABLE "EventSource" (
"address" BLOB NOT NULL,
"abiHash" BLOB NOT NULL,

PRIMARY KEY ("address", "abiHash"),
CONSTRAINT "EventSource_abiHash_fkey" FOREIGN KEY ("abiHash") REFERENCES "EventAbi" ("hash") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "EmitDestination" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"sourceAddress" BLOB NOT NULL,
"abiHash" BLOB NOT NULL,
"webhookUrl" TEXT NOT NULL,
"topic1" BLOB,
"topic2" BLOB,
"topic3" BLOB,
CONSTRAINT "EmitDestination_sourceAddress_abiHash_fkey" FOREIGN KEY ("sourceAddress", "abiHash") REFERENCES "EventSource" ("address", "abiHash") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "User" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"email" TEXT NOT NULL,
"password" TEXT NOT NULL
);

-- CreateTable
CREATE TABLE "Permission" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"userId" INTEGER NOT NULL,
"type" TEXT NOT NULL,
"abiHash" BLOB,
"sourceAddress" BLOB,
"destinationId" INTEGER,
CONSTRAINT "Permission_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "Permission_abiHash_fkey" FOREIGN KEY ("abiHash") REFERENCES "EventAbi" ("hash") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "Permission_abiHash_sourceAddress_fkey" FOREIGN KEY ("abiHash", "sourceAddress") REFERENCES "EventSource" ("abiHash", "address") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "Permission_destinationId_fkey" FOREIGN KEY ("destinationId") REFERENCES "EmitDestination" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateIndex
CREATE UNIQUE INDEX "EmitDestination_sourceAddress_abiHash_webhookUrl_topic1_topic2_topic3_key" ON "EmitDestination"("sourceAddress", "abiHash", "webhookUrl", "topic1", "topic2", "topic3");

-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "sqlite"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would migration work when provider changed to postgres?
(+ eof line?)