From 272a8dbdb2e0048642ba0b5de50d9de798430754 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Sun, 30 Nov 2025 12:13:55 -0600 Subject: [PATCH 1/3] feat: add support for command arguments in application and database schemas - Updated the application, mariadb, mongo, mysql, postgres, and redis schemas to include an optional `args` field for command arguments. - Enhanced the AddCommand and ShowCustomCommand components to handle multiple arguments using a dynamic form. - Modified the database build functions to incorporate the new `args` parameter when creating containers. - Added SQL migrations to update the database schema for existing applications and services to accommodate the new `args` field. --- .../advanced/general/add-command.tsx | 80 +- .../postgres/advanced/show-custom-command.tsx | 75 +- .../drizzle/0123_cloudy_piledriver.sql | 6 + apps/dokploy/drizzle/meta/0123_snapshot.json | 6831 +++++++++++++++++ apps/dokploy/drizzle/meta/_journal.json | 7 + packages/server/src/db/schema/application.ts | 2 + packages/server/src/db/schema/mariadb.ts | 2 + packages/server/src/db/schema/mongo.ts | 2 + packages/server/src/db/schema/mysql.ts | 2 + packages/server/src/db/schema/postgres.ts | 2 + packages/server/src/db/schema/redis.ts | 2 + packages/server/src/utils/builders/index.ts | 15 +- .../server/src/utils/databases/mariadb.ts | 15 +- packages/server/src/utils/databases/mongo.ts | 18 +- packages/server/src/utils/databases/mysql.ts | 15 +- .../server/src/utils/databases/postgres.ts | 15 +- packages/server/src/utils/databases/redis.ts | 14 +- 17 files changed, 7063 insertions(+), 40 deletions(-) create mode 100644 apps/dokploy/drizzle/0123_cloudy_piledriver.sql create mode 100644 apps/dokploy/drizzle/meta/0123_snapshot.json diff --git a/apps/dokploy/components/dashboard/application/advanced/general/add-command.tsx b/apps/dokploy/components/dashboard/application/advanced/general/add-command.tsx index 1bf69394a..e57f21895 100644 --- a/apps/dokploy/components/dashboard/application/advanced/general/add-command.tsx +++ b/apps/dokploy/components/dashboard/application/advanced/general/add-command.tsx @@ -1,6 +1,7 @@ import { zodResolver } from "@hookform/resolvers/zod"; +import { Plus, Trash2 } from "lucide-react"; import { useEffect } from "react"; -import { useForm } from "react-hook-form"; +import { useFieldArray, useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; import { Button } from "@/components/ui/button"; @@ -28,6 +29,13 @@ interface Props { const AddRedirectSchema = z.object({ command: z.string(), + args: z + .array( + z.object({ + value: z.string().min(1, "Argument cannot be empty"), + }), + ) + .optional(), }); type AddCommand = z.infer; @@ -47,22 +55,36 @@ export const AddCommand = ({ applicationId }: Props) => { const form = useForm({ defaultValues: { command: "", + args: [], }, resolver: zodResolver(AddRedirectSchema), }); + const { fields, append, remove } = useFieldArray({ + control: form.control, + name: "args", + }); + useEffect(() => { if (data?.command) { form.reset({ command: data?.command || "", + args: data?.args?.map((arg) => ({ value: arg })) || [], }); } - }, [form, form.reset, form.formState.isSubmitSuccessful, data?.command]); + }, [ + form, + form.reset, + form.formState.isSubmitSuccessful, + data?.command, + data?.args, + ]); const onSubmit = async (data: AddCommand) => { await mutateAsync({ applicationId, command: data?.command, + args: data?.args?.map((arg) => arg.value).filter(Boolean), }) .then(async () => { toast.success("Command Updated"); @@ -100,13 +122,65 @@ export const AddCommand = ({ applicationId }: Props) => { Command - + )} /> + +
+
+ Arguments (Args) + +
+ + {fields.length === 0 && ( +

+ No arguments added yet. Click "Add Argument" to add one. +

+ )} + + {fields.map((field, index) => ( + ( + +
+ + + + +
+ +
+ )} + /> + ))} +
+
+ + {fields.length === 0 && ( +

+ No arguments added yet. Click "Add Argument" to add one. +

+ )} + + {fields.map((field, index) => ( + ( + +
+ + + + +
+ +
+ )} + /> + ))} + +