From ed853fc5f18a9b68d443cd14664d7e91b05c8b09 Mon Sep 17 00:00:00 2001 From: BennyKok Date: Sun, 10 Dec 2023 20:59:23 +0800 Subject: [PATCH] fix: update workflow run with workflow id --- web-plugin/index.js | 2 +- web/drizzle/0003_oval_mockingbird.sql | 6 + web/drizzle/meta/0003_snapshot.json | 353 ++++++++++++++++++++++++++ web/drizzle/meta/_journal.json | 7 + web/src/app/[workflow_id]/page.tsx | 12 +- web/src/app/api/create-run/route.ts | 3 + web/src/db/schema.ts | 5 + 7 files changed, 377 insertions(+), 11 deletions(-) create mode 100644 web/drizzle/0003_oval_mockingbird.sql create mode 100644 web/drizzle/meta/0003_snapshot.json diff --git a/web-plugin/index.js b/web-plugin/index.js index 7bca115..66924ca 100644 --- a/web-plugin/index.js +++ b/web-plugin/index.js @@ -121,7 +121,7 @@ function addButton() { deploy.textContent = "Deploying..."; deploy.style.color = "orange"; - const apiRoute = "http://localhost:3001/api/upload"; + const apiRoute = "http://localhost:3000/api/upload"; const userId = "user_2ZA6vuKD3IJXju16oJVQGLBcWwg"; try { let data = await fetch(apiRoute, { diff --git a/web/drizzle/0003_oval_mockingbird.sql b/web/drizzle/0003_oval_mockingbird.sql new file mode 100644 index 0000000..c885b9d --- /dev/null +++ b/web/drizzle/0003_oval_mockingbird.sql @@ -0,0 +1,6 @@ +ALTER TABLE "comfy_deploy"."workflow_runs" ADD COLUMN "workflow_id" uuid NOT NULL;--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "comfy_deploy"."workflow_runs" ADD CONSTRAINT "workflow_runs_workflow_id_workflows_id_fk" FOREIGN KEY ("workflow_id") REFERENCES "comfy_deploy"."workflows"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; diff --git a/web/drizzle/meta/0003_snapshot.json b/web/drizzle/meta/0003_snapshot.json new file mode 100644 index 0000000..f77fa35 --- /dev/null +++ b/web/drizzle/meta/0003_snapshot.json @@ -0,0 +1,353 @@ +{ + "id": "4e03f61d-b976-41b4-bbad-7655f73bf0fc", + "prevId": "a5fcd4b7-d6f7-4fcc-a826-0d4ed8d3c7dc", + "version": "5", + "dialect": "pg", + "tables": { + "machines": { + "name": "machines", + "schema": "comfy_deploy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "endpoint": { + "name": "endpoint", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "machines_user_id_users_id_fk": { + "name": "machines_user_id_users_id_fk", + "tableFrom": "machines", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "users": { + "name": "users", + "schema": "comfy_deploy", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "workflow_runs": { + "name": "workflow_runs", + "schema": "comfy_deploy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "workflow_version_id": { + "name": "workflow_version_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "machine_id": { + "name": "machine_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "workflow_run_status", + "primaryKey": false, + "notNull": true, + "default": "'not-started'" + }, + "ended_at": { + "name": "ended_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "workflow_runs_workflow_version_id_workflow_versions_id_fk": { + "name": "workflow_runs_workflow_version_id_workflow_versions_id_fk", + "tableFrom": "workflow_runs", + "tableTo": "workflow_versions", + "columnsFrom": [ + "workflow_version_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "workflow_runs_workflow_id_workflows_id_fk": { + "name": "workflow_runs_workflow_id_workflows_id_fk", + "tableFrom": "workflow_runs", + "tableTo": "workflows", + "columnsFrom": [ + "workflow_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "workflow_runs_machine_id_machines_id_fk": { + "name": "workflow_runs_machine_id_machines_id_fk", + "tableFrom": "workflow_runs", + "tableTo": "machines", + "columnsFrom": [ + "machine_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "workflows": { + "name": "workflows", + "schema": "comfy_deploy", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "workflows_user_id_users_id_fk": { + "name": "workflows_user_id_users_id_fk", + "tableFrom": "workflows", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "workflow_versions": { + "name": "workflow_versions", + "schema": "comfy_deploy", + "columns": { + "workflow_id": { + "name": "workflow_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "workflow": { + "name": "workflow", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "workflow_api": { + "name": "workflow_api", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "workflow_versions_workflow_id_workflows_id_fk": { + "name": "workflow_versions_workflow_id_workflows_id_fk", + "tableFrom": "workflow_versions", + "tableTo": "workflows", + "columnsFrom": [ + "workflow_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + } + }, + "enums": { + "workflow_run_status": { + "name": "workflow_run_status", + "values": { + "not-started": "not-started", + "running": "running", + "success": "success", + "failed": "failed" + } + } + }, + "schemas": { + "comfy_deploy": "comfy_deploy" + }, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + } +} \ No newline at end of file diff --git a/web/drizzle/meta/_journal.json b/web/drizzle/meta/_journal.json index 59e0c91..970601c 100644 --- a/web/drizzle/meta/_journal.json +++ b/web/drizzle/meta/_journal.json @@ -22,6 +22,13 @@ "when": 1702044546478, "tag": "0002_clean_khan", "breakpoints": true + }, + { + "idx": 3, + "version": "5", + "when": 1702212969930, + "tag": "0003_oval_mockingbird", + "breakpoints": true } ] } \ No newline at end of file diff --git a/web/src/app/[workflow_id]/page.tsx b/web/src/app/[workflow_id]/page.tsx index 9ec0365..a10ea02 100644 --- a/web/src/app/[workflow_id]/page.tsx +++ b/web/src/app/[workflow_id]/page.tsx @@ -39,16 +39,8 @@ export async function findFirstTableWithVersion(workflow_id: string) { } export async function findAllRuns(workflow_id: string) { - const workflowVersion = await db.query.workflowVersionTable.findFirst({ - where: eq(workflowVersionTable.workflow_id, workflow_id), - }); - - if (!workflowVersion) { - return []; - } - return await db.query.workflowRunsTable.findMany({ - where: eq(workflowRunsTable.workflow_version_id, workflowVersion?.id), + where: eq(workflowRunsTable.workflow_id, workflow_id), orderBy: desc(workflowRunsTable.created_at), with: { machine: { @@ -77,7 +69,7 @@ export default async function Page({ return (
- + {workflow?.name} diff --git a/web/src/app/api/create-run/route.ts b/web/src/app/api/create-run/route.ts index 9e44df1..b563491 100644 --- a/web/src/app/api/create-run/route.ts +++ b/web/src/app/api/create-run/route.ts @@ -78,6 +78,8 @@ export async function POST(request: Request) { }); }); + console.log(result); + // return the error if (result instanceof Response) { return result; @@ -88,6 +90,7 @@ export async function POST(request: Request) { .insert(workflowRunsTable) .values({ id: result.prompt_id, + workflow_id: workflow_version_data.workflow_id, workflow_version_id: workflow_version_data.id, machine_id, }) diff --git a/web/src/db/schema.ts b/web/src/db/schema.ts index f2e65f1..cf12da6 100644 --- a/web/src/db/schema.ts +++ b/web/src/db/schema.ts @@ -75,6 +75,11 @@ export const workflowRunsTable = dbSchema.table("workflow_runs", { .references(() => workflowVersionTable.id, { onDelete: "no action", }), + workflow_id: uuid("workflow_id") + .notNull() + .references(() => workflowTable.id, { + onDelete: "no action", + }), machine_id: uuid("machine_id") .notNull() .references(() => machinesTable.id, {