feat: create the model for the api token

This commit is contained in:
Catalin Pit
2023-11-23 15:21:13 +02:00
parent 5c8a77ee8f
commit 309b56168a
2 changed files with 38 additions and 1 deletions

View File

@ -0,0 +1,21 @@
-- CreateEnum
CREATE TYPE "ApiTokenAlgorithm" AS ENUM ('SHA512');
-- CreateTable
CREATE TABLE "ApiToken" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"token" TEXT NOT NULL,
"algorithm" "ApiTokenAlgorithm" NOT NULL DEFAULT 'SHA512',
"expires" TIMESTAMP(3) NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"userId" INTEGER NOT NULL,
CONSTRAINT "ApiToken_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "ApiToken_token_key" ON "ApiToken"("token");
-- AddForeignKey
ALTER TABLE "ApiToken" ADD CONSTRAINT "ApiToken_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;