-- =============================================================================
-- MPC Service - Database Migration
-- =============================================================================
--
-- mpc-service 作为 MPC 服务网关:
-- 1. 缓存 username + publicKey 的映射关系 (mpc_wallets)
-- 2. 存储 delegate share (mpc_shares)
--
-- =============================================================================

-- CreateTable
CREATE TABLE "mpc_wallets" (
    "id" TEXT NOT NULL,
    "username" VARCHAR(255) NOT NULL,
    "public_key" TEXT NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "mpc_shares" (
    "id" TEXT NOT NULL,
    "username" VARCHAR(255) NOT NULL,
    "party_id" VARCHAR(255) NOT NULL,
    "party_index" INTEGER NOT NULL,
    "encrypted_share" TEXT NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "mpc_wallets_username_key" ON "mpc_wallets"("username");

-- CreateIndex
CREATE INDEX "idx_mw_username" ON "mpc_wallets"("username");

-- CreateIndex (username is unique, so only need unique index)
CREATE UNIQUE INDEX "uq_ms_username" ON "mpc_shares"("username");
