Skip to content

Commit

Permalink
Merge pull request #75 from tensorplex-labs/refactor/criteria-format-…
Browse files Browse the repository at this point in the history
…schema-migration-script

feat: added schema migration script with prisma migrate
  • Loading branch information
codebender37 authored Dec 24, 2024
2 parents d60d574 + c9c160d commit 75b1506
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ repos:
rev: v4.0.1 # Use the latest stable version
hooks:
- id: trailing-whitespace
exclude: ^migrations/
- id: end-of-file-fixer
exclude: ^migrations/
- id: check-yaml
- id: check-added-large-files
- id: check-case-conflict
Expand Down
8 changes: 8 additions & 0 deletions migrations/20241223165717_remove_num_criteria/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- You are about to drop the column `num_criteria` on the `Task` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "Task" DROP COLUMN "num_criteria";
187 changes: 187 additions & 0 deletions migrations/init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
-- CreateEnum
CREATE TYPE "TaskStatus" AS ENUM ('IN_PROGRESS', 'COMPLETED', 'EXPIRED');

-- CreateEnum
CREATE TYPE "TaskResultStatus" AS ENUM ('IN_PROGRESS', 'COMPLETED', 'INVALID');

-- CreateEnum
CREATE TYPE "TaskType" AS ENUM ('CODE_GENERATION', 'DIALOGUE', 'TEXT_TO_IMAGE', 'TEXT_TO_THREE_D');

-- CreateEnum
CREATE TYPE "MetricsType" AS ENUM ('TOTAL_NUM_DOJO_WORKERS', 'TOTAL_NUM_COMPLETED_TASKS', 'TOTAL_NUM_TASK_RESULTS', 'AVERAGE_TASK_COMPLETION_TIME');

-- CreateEnum
CREATE TYPE "EventsType" AS ENUM ('TASK_COMPLETION_TIME');

-- CreateTable
CREATE TABLE "ExternalUser" (
"id" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"name" TEXT NOT NULL,
"email" TEXT NOT NULL,
"is_verified" BOOLEAN NOT NULL DEFAULT false,

CONSTRAINT "ExternalUser_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "ApiKey" (
"id" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"key" TEXT NOT NULL,
"is_delete" BOOLEAN NOT NULL DEFAULT false,
"miner_user_id" TEXT NOT NULL,

CONSTRAINT "ApiKey_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "SubscriptionKey" (
"id" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"key" TEXT NOT NULL,
"is_delete" BOOLEAN NOT NULL DEFAULT false,
"miner_user_id" TEXT NOT NULL,

CONSTRAINT "SubscriptionKey_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "MinerUser" (
"id" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"hotkey" TEXT NOT NULL,
"email" TEXT,
"organizationName" TEXT,

CONSTRAINT "MinerUser_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Task" (
"id" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"expire_at" TIMESTAMP(3) NOT NULL,
"title" TEXT NOT NULL,
"body" TEXT NOT NULL,
"type" "TaskType" NOT NULL,
"task_data" JSONB NOT NULL,
"status" "TaskStatus" NOT NULL,
"max_results" INTEGER NOT NULL,
"num_results" INTEGER NOT NULL,
"num_criteria" INTEGER NOT NULL,
"total_reward" DOUBLE PRECISION,
"miner_user_id" TEXT,

CONSTRAINT "Task_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "TaskResult" (
"id" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"status" "TaskResultStatus" NOT NULL,
"result_data" JSONB NOT NULL,
"task_id" TEXT NOT NULL,
"worker_id" TEXT NOT NULL,
"stake_amount" DOUBLE PRECISION,
"potential_reward" DOUBLE PRECISION,
"potential_loss" DOUBLE PRECISION,
"finalised_reward" DOUBLE PRECISION,
"finalised_loss" DOUBLE PRECISION,

CONSTRAINT "TaskResult_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "DojoWorker" (
"id" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"wallet_address" TEXT NOT NULL,
"chain_id" TEXT NOT NULL,
"current_stake_amount" DOUBLE PRECISION,

CONSTRAINT "DojoWorker_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "WorkerPartner" (
"id" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"miner_subscription_key" TEXT NOT NULL,
"worker_id" TEXT NOT NULL,
"is_delete_by_miner" BOOLEAN NOT NULL DEFAULT false,
"is_delete_by_worker" BOOLEAN NOT NULL DEFAULT false,
"name" TEXT,

CONSTRAINT "WorkerPartner_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Metrics" (
"id" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"type" "MetricsType" NOT NULL,
"metrics_data" JSONB NOT NULL,

CONSTRAINT "Metrics_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Events" (
"id" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"type" "EventsType" NOT NULL,
"events_data" JSONB NOT NULL,

CONSTRAINT "Events_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "ApiKey_key_key" ON "ApiKey"("key");

-- CreateIndex
CREATE UNIQUE INDEX "SubscriptionKey_key_key" ON "SubscriptionKey"("key");

-- CreateIndex
CREATE UNIQUE INDEX "MinerUser_hotkey_key" ON "MinerUser"("hotkey");

-- CreateIndex
CREATE UNIQUE INDEX "DojoWorker_wallet_address_chain_id_key" ON "DojoWorker"("wallet_address", "chain_id");

-- CreateIndex
CREATE UNIQUE INDEX "WorkerPartner_miner_subscription_key_worker_id_key" ON "WorkerPartner"("miner_subscription_key", "worker_id");

-- CreateIndex
CREATE UNIQUE INDEX "Metrics_type_key" ON "Metrics"("type");

-- AddForeignKey
ALTER TABLE "ApiKey" ADD CONSTRAINT "ApiKey_miner_user_id_fkey" FOREIGN KEY ("miner_user_id") REFERENCES "MinerUser"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "SubscriptionKey" ADD CONSTRAINT "SubscriptionKey_miner_user_id_fkey" FOREIGN KEY ("miner_user_id") REFERENCES "MinerUser"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Task" ADD CONSTRAINT "Task_miner_user_id_fkey" FOREIGN KEY ("miner_user_id") REFERENCES "MinerUser"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TaskResult" ADD CONSTRAINT "TaskResult_task_id_fkey" FOREIGN KEY ("task_id") REFERENCES "Task"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TaskResult" ADD CONSTRAINT "TaskResult_worker_id_fkey" FOREIGN KEY ("worker_id") REFERENCES "DojoWorker"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "WorkerPartner" ADD CONSTRAINT "WorkerPartner_miner_subscription_key_fkey" FOREIGN KEY ("miner_subscription_key") REFERENCES "SubscriptionKey"("key") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "WorkerPartner" ADD CONSTRAINT "WorkerPartner_worker_id_fkey" FOREIGN KEY ("worker_id") REFERENCES "DojoWorker"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
3 changes: 3 additions & 0 deletions 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 = "postgresql"

0 comments on commit 75b1506

Please sign in to comment.