-
Notifications
You must be signed in to change notification settings - Fork 44.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backend): Add API key DB table (#8593)
* add api key db tables * remove uniqueness constraint on prefix * add postfix
- Loading branch information
1 parent
f719c7e
commit 359ae83
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
autogpt_platform/backend/migrations/20241108170448_add_api_key_support/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
-- CreateEnum | ||
CREATE TYPE "APIKeyPermission" AS ENUM ('EXECUTE_GRAPH', 'READ_GRAPH', 'EXECUTE_BLOCK', 'READ_BLOCK'); | ||
|
||
-- CreateEnum | ||
CREATE TYPE "APIKeyStatus" AS ENUM ('ACTIVE', 'REVOKED', 'SUSPENDED'); | ||
|
||
-- CreateTable | ||
CREATE TABLE "APIKey" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"prefix" TEXT NOT NULL, | ||
"postfix" TEXT NOT NULL, | ||
"key" TEXT NOT NULL, | ||
"status" "APIKeyStatus" NOT NULL DEFAULT 'ACTIVE', | ||
"permissions" "APIKeyPermission"[], | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"lastUsedAt" TIMESTAMP(3), | ||
"revokedAt" TIMESTAMP(3), | ||
"description" TEXT, | ||
"userId" TEXT NOT NULL, | ||
|
||
CONSTRAINT "APIKey_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "APIKey_key_key" ON "APIKey"("key"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "APIKey_key_idx" ON "APIKey"("key"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "APIKey_prefix_idx" ON "APIKey"("prefix"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "APIKey_userId_idx" ON "APIKey"("userId"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "APIKey_status_idx" ON "APIKey"("status"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "APIKey_userId_status_idx" ON "APIKey"("userId", "status"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "APIKey" ADD CONSTRAINT "APIKey_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters