-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a02c81
commit 46a368d
Showing
16 changed files
with
1,033 additions
and
88 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
packages/backend/server/migrations/20240325125057_ai_sessions/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
90 changes: 90 additions & 0 deletions
90
packages/backend/server/migrations/20240402100608_ai_prompt_session_metadata/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,90 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the `ai_prompts` table. If the table is not empty, all the data it contains will be lost. | ||
- You are about to drop the `ai_sessions` table. If the table is not empty, all the data it contains will be lost. | ||
*/ | ||
-- DropForeignKey | ||
ALTER TABLE "ai_sessions" DROP CONSTRAINT "ai_sessions_doc_id_workspace_id_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "ai_sessions" DROP CONSTRAINT "ai_sessions_user_id_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "ai_sessions" DROP CONSTRAINT "ai_sessions_workspace_id_fkey"; | ||
|
||
-- DropTable | ||
DROP TABLE "ai_prompts"; | ||
|
||
-- DropTable | ||
DROP TABLE "ai_sessions"; | ||
|
||
-- CreateTable | ||
CREATE TABLE "ai_prompts_messages" ( | ||
"prompt_id" INTEGER NOT NULL, | ||
"idx" INTEGER NOT NULL, | ||
"role" "AiPromptRole" NOT NULL, | ||
"content" TEXT NOT NULL, | ||
"params" JSON, | ||
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "ai_prompts_metadata" ( | ||
"id" SERIAL NOT NULL, | ||
"name" VARCHAR(32) NOT NULL, | ||
"action" VARCHAR, | ||
"model" VARCHAR, | ||
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "ai_prompts_metadata_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "ai_sessions_messages" ( | ||
"id" VARCHAR(36) NOT NULL, | ||
"session_id" VARCHAR(36) NOT NULL, | ||
"role" "AiPromptRole" NOT NULL, | ||
"content" TEXT NOT NULL, | ||
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMPTZ(6) NOT NULL, | ||
|
||
CONSTRAINT "ai_sessions_messages_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "ai_sessions_metadata" ( | ||
"id" VARCHAR(36) NOT NULL, | ||
"user_id" VARCHAR(36) NOT NULL, | ||
"workspace_id" VARCHAR(36) NOT NULL, | ||
"doc_id" VARCHAR(36) NOT NULL, | ||
"prompt_name" VARCHAR(32) NOT NULL, | ||
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "ai_sessions_metadata_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "ai_prompts_messages_prompt_id_idx_key" ON "ai_prompts_messages"("prompt_id", "idx"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "ai_prompts_metadata_name_key" ON "ai_prompts_metadata"("name"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ai_prompts_messages" ADD CONSTRAINT "ai_prompts_messages_prompt_id_fkey" FOREIGN KEY ("prompt_id") REFERENCES "ai_prompts_metadata"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ai_sessions_messages" ADD CONSTRAINT "ai_sessions_messages_session_id_fkey" FOREIGN KEY ("session_id") REFERENCES "ai_sessions_metadata"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ai_sessions_metadata" ADD CONSTRAINT "ai_sessions_metadata_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ai_sessions_metadata" ADD CONSTRAINT "ai_sessions_metadata_workspace_id_fkey" FOREIGN KEY ("workspace_id") REFERENCES "workspaces"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ai_sessions_metadata" ADD CONSTRAINT "ai_sessions_metadata_doc_id_workspace_id_fkey" FOREIGN KEY ("doc_id", "workspace_id") REFERENCES "snapshots"("guid", "workspace_id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ai_sessions_metadata" ADD CONSTRAINT "ai_sessions_metadata_prompt_name_fkey" FOREIGN KEY ("prompt_name") REFERENCES "ai_prompts_metadata"("name") 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
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
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
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
33 changes: 33 additions & 0 deletions
33
packages/backend/server/src/data/migrations/1712068777394-prompts.ts
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,33 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
|
||
import { prompts } from './utils/prompts'; | ||
|
||
export class Prompts1712068777394 { | ||
// do the migration | ||
static async up(db: PrismaClient) { | ||
await db.$transaction(async tx => { | ||
await Promise.all( | ||
prompts.map(prompt => | ||
tx.aiPrompt.create({ | ||
data: { | ||
name: prompt.name, | ||
action: prompt.action, | ||
model: prompt.model, | ||
messages: { | ||
create: prompt.messages.map((message, idx) => ({ | ||
idx, | ||
role: message.role, | ||
content: message.content, | ||
params: message.params, | ||
})), | ||
}, | ||
}, | ||
}) | ||
) | ||
); | ||
}); | ||
} | ||
|
||
// revert the migration | ||
static async down(_db: PrismaClient) {} | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/backend/server/src/data/migrations/1712224382221-refresh-free-plan.ts
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,16 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
|
||
import { Quotas } from '../../core/quota'; | ||
import { upgradeQuotaVersion } from './utils/user-quotas'; | ||
|
||
export class RefreshFreePlan1712224382221 { | ||
// do the migration | ||
static async up(db: PrismaClient) { | ||
// free plan 1.0 | ||
const quota = Quotas[4]; | ||
await upgradeQuotaVersion(db, quota, 'free plan 1.1 migration'); | ||
} | ||
|
||
// revert the migration | ||
static async down(_db: PrismaClient) {} | ||
} |
Oops, something went wrong.