refactor: update project structure to use environmentId instead of projectId across components and API routes; implement environment management features

This commit is contained in:
Mauricio Siu
2025-09-01 19:48:20 -06:00
parent 6fc325fe95
commit 72f8a28f4f
31 changed files with 8527 additions and 1401 deletions
@@ -1,10 +1,10 @@
import { TemplateGenerator } from "@/components/dashboard/project/ai/template-generator"; import { TemplateGenerator } from "@/components/dashboard/project/ai/template-generator";
interface Props { interface Props {
projectId: string; environmentId: string;
projectName?: string; projectName?: string;
} }
export const AddAiAssistant = ({ projectId }: Props) => { export const AddAiAssistant = ({ environmentId }: Props) => {
return <TemplateGenerator projectId={projectId} />; return <TemplateGenerator environmentId={environmentId} />;
}; };
@@ -64,11 +64,11 @@ const AddTemplateSchema = z.object({
type AddTemplate = z.infer<typeof AddTemplateSchema>; type AddTemplate = z.infer<typeof AddTemplateSchema>;
interface Props { interface Props {
projectId: string; environmentId: string;
projectName?: string; projectName?: string;
} }
export const AddApplication = ({ projectId, projectName }: Props) => { export const AddApplication = ({ environmentId, projectName }: Props) => {
const utils = api.useUtils(); const utils = api.useUtils();
const { data: isCloud } = api.settings.isCloud.useQuery(); const { data: isCloud } = api.settings.isCloud.useQuery();
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
@@ -94,15 +94,15 @@ export const AddApplication = ({ projectId, projectName }: Props) => {
name: data.name, name: data.name,
appName: data.appName, appName: data.appName,
description: data.description, description: data.description,
projectId, environmentId,
serverId: data.serverId, serverId: data.serverId,
}) })
.then(async () => { .then(async () => {
toast.success("Service Created"); toast.success("Service Created");
form.reset(); form.reset();
setVisible(false); setVisible(false);
await utils.project.one.invalidate({ await utils.environment.one.invalidate({
projectId, environmentId,
}); });
}) })
.catch(() => { .catch(() => {
@@ -65,11 +65,11 @@ const AddComposeSchema = z.object({
type AddCompose = z.infer<typeof AddComposeSchema>; type AddCompose = z.infer<typeof AddComposeSchema>;
interface Props { interface Props {
projectId: string; environmentId: string;
projectName?: string; projectName?: string;
} }
export const AddCompose = ({ projectId, projectName }: Props) => { export const AddCompose = ({ environmentId, projectName }: Props) => {
const utils = api.useUtils(); const utils = api.useUtils();
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const slug = slugify(projectName); const slug = slugify(projectName);
@@ -78,6 +78,9 @@ export const AddCompose = ({ projectId, projectName }: Props) => {
const { mutateAsync, isLoading, error, isError } = const { mutateAsync, isLoading, error, isError } =
api.compose.create.useMutation(); api.compose.create.useMutation();
// Get environment data to extract projectId
const { data: environment } = api.environment.one.useQuery({ environmentId });
const hasServers = servers && servers.length > 0; const hasServers = servers && servers.length > 0;
const form = useForm<AddCompose>({ const form = useForm<AddCompose>({
@@ -98,7 +101,7 @@ export const AddCompose = ({ projectId, projectName }: Props) => {
await mutateAsync({ await mutateAsync({
name: data.name, name: data.name,
description: data.description, description: data.description,
projectId, environmentId,
composeType: data.composeType, composeType: data.composeType,
appName: data.appName, appName: data.appName,
serverId: data.serverId, serverId: data.serverId,
@@ -106,8 +109,9 @@ export const AddCompose = ({ projectId, projectName }: Props) => {
.then(async () => { .then(async () => {
toast.success("Compose Created"); toast.success("Compose Created");
setVisible(false); setVisible(false);
await utils.project.one.invalidate({ // Invalidate the project query to refresh the environment data
projectId, await utils.environment.one.invalidate({
environmentId,
}); });
}) })
.catch(() => { .catch(() => {
@@ -170,11 +170,11 @@ const databasesMap = {
type AddDatabase = z.infer<typeof mySchema>; type AddDatabase = z.infer<typeof mySchema>;
interface Props { interface Props {
projectId: string; environmentId: string;
projectName?: string; projectName?: string;
} }
export const AddDatabase = ({ projectId, projectName }: Props) => { export const AddDatabase = ({ environmentId, projectName }: Props) => {
const utils = api.useUtils(); const utils = api.useUtils();
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const slug = slugify(projectName); const slug = slugify(projectName);
@@ -185,6 +185,9 @@ export const AddDatabase = ({ projectId, projectName }: Props) => {
const mariadbMutation = api.mariadb.create.useMutation(); const mariadbMutation = api.mariadb.create.useMutation();
const mysqlMutation = api.mysql.create.useMutation(); const mysqlMutation = api.mysql.create.useMutation();
// Get environment data to extract projectId
const { data: environment } = api.environment.one.useQuery({ environmentId });
const hasServers = servers && servers.length > 0; const hasServers = servers && servers.length > 0;
const form = useForm<AddDatabase>({ const form = useForm<AddDatabase>({
@@ -219,7 +222,8 @@ export const AddDatabase = ({ projectId, projectName }: Props) => {
name: data.name, name: data.name,
appName: data.appName, appName: data.appName,
dockerImage: defaultDockerImage, dockerImage: defaultDockerImage,
projectId, projectId: environment?.projectId || "",
environmentId,
serverId: data.serverId, serverId: data.serverId,
description: data.description, description: data.description,
}; };
@@ -248,7 +252,6 @@ export const AddDatabase = ({ projectId, projectName }: Props) => {
...commonParams, ...commonParams,
databasePassword: data.databasePassword, databasePassword: data.databasePassword,
serverId: data.serverId, serverId: data.serverId,
projectId,
}); });
} else if (data.type === "mariadb") { } else if (data.type === "mariadb") {
promise = mariadbMutation.mutateAsync({ promise = mariadbMutation.mutateAsync({
@@ -287,8 +290,9 @@ export const AddDatabase = ({ projectId, projectName }: Props) => {
databaseUser: "", databaseUser: "",
}); });
setVisible(false); setVisible(false);
await utils.project.one.invalidate({ // Invalidate the project query to refresh the environment data
projectId, await utils.environment.one.invalidate({
environmentId,
}); });
}) })
.catch(() => { .catch(() => {
@@ -73,11 +73,11 @@ import { api } from "@/utils/api";
const TEMPLATE_BASE_URL_KEY = "dokploy_template_base_url"; const TEMPLATE_BASE_URL_KEY = "dokploy_template_base_url";
interface Props { interface Props {
projectId: string; environmentId: string;
baseUrl?: string; baseUrl?: string;
} }
export const AddTemplate = ({ projectId, baseUrl }: Props) => { export const AddTemplate = ({ environmentId, baseUrl }: Props) => {
const [query, setQuery] = useState(""); const [query, setQuery] = useState("");
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [viewMode, setViewMode] = useState<"detailed" | "icon">("detailed"); const [viewMode, setViewMode] = useState<"detailed" | "icon">("detailed");
@@ -91,6 +91,9 @@ export const AddTemplate = ({ projectId, baseUrl }: Props) => {
return undefined; return undefined;
}); });
// Get environment data to extract projectId
const { data: environment } = api.environment.one.useQuery({ environmentId });
// Save to localStorage when customBaseUrl changes // Save to localStorage when customBaseUrl changes
useEffect(() => { useEffect(() => {
if (customBaseUrl) { if (customBaseUrl) {
@@ -490,7 +493,7 @@ export const AddTemplate = ({ projectId, baseUrl }: Props) => {
disabled={isLoading} disabled={isLoading}
onClick={async () => { onClick={async () => {
const promise = mutateAsync({ const promise = mutateAsync({
projectId, environmentId,
serverId: serverId || undefined, serverId: serverId || undefined,
id: template.id, id: template.id,
baseUrl: customBaseUrl, baseUrl: customBaseUrl,
@@ -498,8 +501,9 @@ export const AddTemplate = ({ projectId, baseUrl }: Props) => {
toast.promise(promise, { toast.promise(promise, {
loading: "Setting up...", loading: "Setting up...",
success: () => { success: () => {
utils.project.one.invalidate({ // Invalidate the project query to refresh the environment data
projectId, utils.environment.one.invalidate({
environmentId,
}); });
setOpen(false); setOpen(false);
return `${template.name} template created successfully`; return `${template.name} template created successfully`;
@@ -0,0 +1,382 @@
import { useState } from "react";
import { useRouter } from "next/router";
import { api } from "@/utils/api";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea";
import { toast } from "sonner";
import { ChevronDownIcon, PlusIcon, PencilIcon, TrashIcon } from "lucide-react";
interface Environment {
environmentId: string;
name: string;
description?: string | null;
createdAt: string;
}
interface AdvancedEnvironmentSelectorProps {
projectId: string;
environments: Environment[];
currentEnvironmentId?: string;
}
export const AdvancedEnvironmentSelector = ({
projectId,
environments,
currentEnvironmentId,
}: AdvancedEnvironmentSelectorProps) => {
const router = useRouter();
const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false);
const [isEditDialogOpen, setIsEditDialogOpen] = useState(false);
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false);
const [selectedEnvironment, setSelectedEnvironment] = useState<Environment | null>(null);
// Form states
const [name, setName] = useState("");
const [description, setDescription] = useState("");
// API mutations
const createEnvironment = api.environment.create.useMutation();
const updateEnvironment = api.environment.update.useMutation();
const deleteEnvironment = api.environment.remove.useMutation();
const duplicateEnvironment = api.environment.duplicate.useMutation();
// Refetch project data
const utils = api.useUtils();
const handleCreateEnvironment = async () => {
try {
await createEnvironment.mutateAsync({
projectId,
name: name.trim(),
description: description.trim() || null,
});
toast.success("Environment created successfully");
utils.project.one.invalidate({ projectId });
setIsCreateDialogOpen(false);
setName("");
setDescription("");
} catch (error) {
toast.error("Failed to create environment");
}
};
const handleUpdateEnvironment = async () => {
if (!selectedEnvironment) return;
try {
await updateEnvironment.mutateAsync({
environmentId: selectedEnvironment.environmentId,
name: name.trim(),
description: description.trim() || null,
});
toast.success("Environment updated successfully");
utils.project.one.invalidate({ projectId });
setIsEditDialogOpen(false);
setSelectedEnvironment(null);
setName("");
setDescription("");
} catch (error) {
toast.error("Failed to update environment");
}
};
const handleDeleteEnvironment = async () => {
if (!selectedEnvironment) return;
try {
await deleteEnvironment.mutateAsync({
environmentId: selectedEnvironment.environmentId,
});
toast.success("Environment deleted successfully");
utils.project.one.invalidate({ projectId });
setIsDeleteDialogOpen(false);
setSelectedEnvironment(null);
// Redirect to production if we deleted the current environment
if (selectedEnvironment.environmentId === currentEnvironmentId) {
const productionEnv = environments.find(env => env.name === "production");
if (productionEnv) {
router.push(`/dashboard/project/${projectId}/environment/${productionEnv.environmentId}`);
}
}
} catch (error) {
toast.error("Failed to delete environment");
}
};
const handleDuplicateEnvironment = async (environment: Environment) => {
try {
const result = await duplicateEnvironment.mutateAsync({
environmentId: environment.environmentId,
name: `${environment.name}-copy`,
description: environment.description,
});
toast.success("Environment duplicated successfully");
utils.project.one.invalidate({ projectId });
// Navigate to the new duplicated environment
router.push(`/dashboard/project/${projectId}/environment/${result.environmentId}`);
} catch (error) {
toast.error("Failed to duplicate environment");
}
};
const openEditDialog = (environment: Environment) => {
setSelectedEnvironment(environment);
setName(environment.name);
setDescription(environment.description || "");
setIsEditDialogOpen(true);
};
const openDeleteDialog = (environment: Environment) => {
setSelectedEnvironment(environment);
setIsDeleteDialogOpen(true);
};
const currentEnv = environments.find(env => env.environmentId === currentEnvironmentId);
return (
<>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" className="min-w-[200px] justify-between">
<div className="flex items-center gap-2">
<span>{currentEnv?.name || "Select Environment"}</span>
{currentEnv?.name === "production" && (
<span className="px-1.5 py-0.5 text-xs bg-green-100 text-green-800 rounded">
Prod
</span>
)}
</div>
<ChevronDownIcon className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-[300px]" align="start">
<DropdownMenuLabel>Environments</DropdownMenuLabel>
<DropdownMenuSeparator />
{environments.map((environment) => (
<div key={environment.environmentId} className="flex items-center">
<DropdownMenuItem
className="flex-1 cursor-pointer"
onClick={() => {
router.push(`/dashboard/project/${projectId}/environment/${environment.environmentId}`);
}}
>
<div className="flex items-center justify-between w-full">
<div className="flex items-center gap-2">
<span>{environment.name}</span>
{environment.name === "production" && (
<span className="px-1.5 py-0.5 text-xs bg-green-100 text-green-800 rounded">
Prod
</span>
)}
</div>
{environment.environmentId === currentEnvironmentId && (
<div className="w-2 h-2 bg-blue-500 rounded-full" />
)}
</div>
</DropdownMenuItem>
{/* Action buttons for non-production environments */}
{environment.name !== "production" && (
<div className="flex items-center gap-1 px-2">
<Button
variant="ghost"
size="sm"
className="h-6 w-6 p-0"
onClick={(e) => {
e.stopPropagation();
openEditDialog(environment);
}}
>
<PencilIcon className="h-3 w-3" />
</Button>
<Button
variant="ghost"
size="sm"
className="h-6 w-6 p-0 text-red-600 hover:text-red-700"
onClick={(e) => {
e.stopPropagation();
openDeleteDialog(environment);
}}
>
<TrashIcon className="h-3 w-3" />
</Button>
</div>
)}
</div>
))}
<DropdownMenuSeparator />
<DropdownMenuItem
className="cursor-pointer"
onClick={() => setIsCreateDialogOpen(true)}
>
<PlusIcon className="h-4 w-4 mr-2" />
Create Environment
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
{/* Create Environment Dialog */}
<Dialog open={isCreateDialogOpen} onOpenChange={setIsCreateDialogOpen}>
<DialogContent>
<DialogHeader>
<DialogTitle>Create Environment</DialogTitle>
<DialogDescription>
Create a new environment for your project.
</DialogDescription>
</DialogHeader>
<div className="space-y-4">
<div>
<Label htmlFor="name">Name</Label>
<Input
id="name"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Environment name"
/>
</div>
<div>
<Label htmlFor="description">Description (optional)</Label>
<Textarea
id="description"
value={description}
onChange={(e) => setDescription(e.target.value)}
placeholder="Environment description"
/>
</div>
</div>
<DialogFooter>
<Button
variant="outline"
onClick={() => {
setIsCreateDialogOpen(false);
setName("");
setDescription("");
}}
>
Cancel
</Button>
<Button
onClick={handleCreateEnvironment}
disabled={!name.trim() || createEnvironment.isPending}
>
{createEnvironment.isPending ? "Creating..." : "Create"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
{/* Edit Environment Dialog */}
<Dialog open={isEditDialogOpen} onOpenChange={setIsEditDialogOpen}>
<DialogContent>
<DialogHeader>
<DialogTitle>Edit Environment</DialogTitle>
<DialogDescription>
Update the environment details.
</DialogDescription>
</DialogHeader>
<div className="space-y-4">
<div>
<Label htmlFor="edit-name">Name</Label>
<Input
id="edit-name"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Environment name"
/>
</div>
<div>
<Label htmlFor="edit-description">Description (optional)</Label>
<Textarea
id="edit-description"
value={description}
onChange={(e) => setDescription(e.target.value)}
placeholder="Environment description"
/>
</div>
</div>
<DialogFooter>
<Button
variant="outline"
onClick={() => {
setIsEditDialogOpen(false);
setSelectedEnvironment(null);
setName("");
setDescription("");
}}
>
Cancel
</Button>
<Button
onClick={handleUpdateEnvironment}
disabled={!name.trim() || updateEnvironment.isPending}
>
{updateEnvironment.isPending ? "Updating..." : "Update"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
{/* Delete Environment Dialog */}
<Dialog open={isDeleteDialogOpen} onOpenChange={setIsDeleteDialogOpen}>
<DialogContent>
<DialogHeader>
<DialogTitle>Delete Environment</DialogTitle>
<DialogDescription>
Are you sure you want to delete the environment "{selectedEnvironment?.name}"?
This action cannot be undone and will also delete all services in this environment.
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button
variant="outline"
onClick={() => {
setIsDeleteDialogOpen(false);
setSelectedEnvironment(null);
}}
>
Cancel
</Button>
<Button
variant="destructive"
onClick={handleDeleteEnvironment}
disabled={deleteEnvironment.isPending}
>
{deleteEnvironment.isPending ? "Deleting..." : "Delete"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</>
);
};
@@ -90,11 +90,11 @@ export const { useStepper, steps, Scoped } = defineStepper(
); );
interface Props { interface Props {
projectId: string; environmentId: string;
projectName?: string; projectName?: string;
} }
export const TemplateGenerator = ({ projectId }: Props) => { export const TemplateGenerator = ({ environmentId }: Props) => {
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const stepper = useStepper(); const stepper = useStepper();
const { data: aiSettings } = api.ai.getAll.useQuery(); const { data: aiSettings } = api.ai.getAll.useQuery();
@@ -103,6 +103,9 @@ export const TemplateGenerator = ({ projectId }: Props) => {
useState<TemplateInfo>(defaultTemplateInfo); useState<TemplateInfo>(defaultTemplateInfo);
const utils = api.useUtils(); const utils = api.useUtils();
// Get environment data to extract projectId
const { data: environment } = api.environment.one.useQuery({ environmentId });
const haveAtleasOneProviderEnabled = aiSettings?.some( const haveAtleasOneProviderEnabled = aiSettings?.some(
(ai) => ai.isEnabled === true, (ai) => ai.isEnabled === true,
); );
@@ -121,7 +124,7 @@ export const TemplateGenerator = ({ projectId }: Props) => {
const onSubmit = async () => { const onSubmit = async () => {
await mutateAsync({ await mutateAsync({
projectId, projectId: environment?.projectId || "",
id: templateInfo.details?.id || "", id: templateInfo.details?.id || "",
name: templateInfo?.details?.name || "", name: templateInfo?.details?.name || "",
description: templateInfo?.details?.shortDescription || "", description: templateInfo?.details?.shortDescription || "",
@@ -138,9 +141,8 @@ export const TemplateGenerator = ({ projectId }: Props) => {
.then(async () => { .then(async () => {
toast.success("Compose Created"); toast.success("Compose Created");
setOpen(false); setOpen(false);
await utils.project.one.invalidate({ // Invalidate the project query to refresh the environment data
projectId, await utils.project.one.invalidate();
});
}) })
.catch(() => { .catch(() => {
toast.error("Error creating the compose"); toast.error("Error creating the compose");
@@ -96,22 +96,8 @@ export const ShowProjects = () => {
new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime(); new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime();
break; break;
case "services": { case "services": {
const aTotalServices = const aTotalServices = a.environments.length;
a.mariadb.length + const bTotalServices = b.environments.length;
a.mongo.length +
a.mysql.length +
a.postgres.length +
a.redis.length +
a.applications.length +
a.compose.length;
const bTotalServices =
b.mariadb.length +
b.mongo.length +
b.mysql.length +
b.postgres.length +
b.redis.length +
b.applications.length +
b.compose.length;
comparison = aTotalServices - bTotalServices; comparison = aTotalServices - bTotalServices;
break; break;
} }
@@ -201,23 +187,23 @@ export const ShowProjects = () => {
)} )}
<div className="w-full grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 3xl:grid-cols-5 flex-wrap gap-5"> <div className="w-full grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 3xl:grid-cols-5 flex-wrap gap-5">
{filteredProjects?.map((project) => { {filteredProjects?.map((project) => {
const emptyServices = // const emptyServices =
project?.mariadb.length === 0 && // project?.environments.length === 0 &&
project?.mongo.length === 0 && // project?.mongo.length === 0 &&
project?.mysql.length === 0 && // project?.environments.mysql.length === 0 &&
project?.postgres.length === 0 && // project?.environments.postgres.length === 0 &&
project?.redis.length === 0 && // project?.environments.redis.length === 0 &&
project?.applications.length === 0 && // project?.applications.length === 0 &&
project?.compose.length === 0; // project?.compose.length === 0;
const totalServices = // const totalServices =
project?.mariadb.length + // project?.mariadb.length +
project?.mongo.length + // project?.mongo.length +
project?.mysql.length + // project?.mysql.length +
project?.postgres.length + // project?.postgres.length +
project?.redis.length + // project?.redis.length +
project?.applications.length + // project?.applications.length +
project?.compose.length; // project?.compose.length;
return ( return (
<div <div
@@ -228,7 +214,7 @@ export const ShowProjects = () => {
href={`/dashboard/project/${project.projectId}`} href={`/dashboard/project/${project.projectId}`}
> >
<Card className="group relative w-full h-full bg-transparent transition-colors hover:bg-border"> <Card className="group relative w-full h-full bg-transparent transition-colors hover:bg-border">
{project.applications.length > 0 || {/* {project.applications.length > 0 ||
project.compose.length > 0 ? ( project.compose.length > 0 ? (
<DropdownMenu> <DropdownMenu>
<DropdownMenuTrigger asChild> <DropdownMenuTrigger asChild>
@@ -322,7 +308,7 @@ export const ShowProjects = () => {
)} )}
</DropdownMenuContent> </DropdownMenuContent>
</DropdownMenu> </DropdownMenu>
) : null} ) : null} */}
<CardHeader> <CardHeader>
<CardTitle className="flex items-center justify-between gap-2"> <CardTitle className="flex items-center justify-between gap-2">
<span className="flex flex-col gap-1.5"> <span className="flex flex-col gap-1.5">
@@ -393,7 +379,7 @@ export const ShowProjects = () => {
Are you sure to delete this Are you sure to delete this
project? project?
</AlertDialogTitle> </AlertDialogTitle>
{!emptyServices ? ( {/* {!emptyServices ? (
<div className="flex flex-row gap-4 rounded-lg bg-yellow-50 p-2 dark:bg-yellow-950"> <div className="flex flex-row gap-4 rounded-lg bg-yellow-50 p-2 dark:bg-yellow-950">
<AlertTriangle className="text-yellow-600 dark:text-yellow-400" /> <AlertTriangle className="text-yellow-600 dark:text-yellow-400" />
<span className="text-sm text-yellow-600 dark:text-yellow-400"> <span className="text-sm text-yellow-600 dark:text-yellow-400">
@@ -407,14 +393,14 @@ export const ShowProjects = () => {
This action cannot be This action cannot be
undone undone
</AlertDialogDescription> </AlertDialogDescription>
)} )} */}
</AlertDialogHeader> </AlertDialogHeader>
<AlertDialogFooter> <AlertDialogFooter>
<AlertDialogCancel> <AlertDialogCancel>
Cancel Cancel
</AlertDialogCancel> </AlertDialogCancel>
<AlertDialogAction <AlertDialogAction
disabled={!emptyServices} // disabled={!emptyServices}
onClick={async () => { onClick={async () => {
await mutateAsync({ await mutateAsync({
projectId: projectId:
@@ -452,12 +438,12 @@ export const ShowProjects = () => {
<DateTooltip date={project.createdAt}> <DateTooltip date={project.createdAt}>
Created Created
</DateTooltip> </DateTooltip>
<span> {/* <span>
{totalServices}{" "} {totalServices}{" "}
{totalServices === 1 {totalServices === 1
? "service" ? "service"
: "services"} : "services"}
</span> </span> */}
</div> </div>
</CardFooter> </CardFooter>
</Card> </Card>
@@ -20,10 +20,10 @@ import {
CommandSeparator, CommandSeparator,
} from "@/components/ui/command"; } from "@/components/ui/command";
import { authClient } from "@/lib/auth-client"; import { authClient } from "@/lib/auth-client";
import { // import {
extractServices, // extractServices,
type Services, // type Services,
} from "@/pages/dashboard/project/[projectId]"; // } from "@/pages/dashboard/project/[projectId]";
import { api } from "@/utils/api"; import { api } from "@/utils/api";
import { StatusTooltip } from "../shared/status-tooltip"; import { StatusTooltip } from "../shared/status-tooltip";
@@ -51,7 +51,7 @@ export const SearchCommand = () => {
return ( return (
<div> <div>
<CommandDialog open={open} onOpenChange={setOpen}> {/* <CommandDialog open={open} onOpenChange={setOpen}>
<CommandInput <CommandInput
placeholder={"Search projects or settings"} placeholder={"Search projects or settings"}
value={search} value={search}
@@ -181,7 +181,7 @@ export const SearchCommand = () => {
</CommandItem> </CommandItem>
</CommandGroup> </CommandGroup>
</CommandList> </CommandList>
</CommandDialog> </CommandDialog> */}
</div> </div>
); );
}; };
@@ -0,0 +1,23 @@
ALTER TABLE "application" DROP CONSTRAINT "application_projectId_project_projectId_fk";
--> statement-breakpoint
ALTER TABLE "compose" DROP CONSTRAINT "compose_projectId_project_projectId_fk";
--> statement-breakpoint
ALTER TABLE "mariadb" DROP CONSTRAINT "mariadb_projectId_project_projectId_fk";
--> statement-breakpoint
ALTER TABLE "mongo" DROP CONSTRAINT "mongo_projectId_project_projectId_fk";
--> statement-breakpoint
ALTER TABLE "mysql" DROP CONSTRAINT "mysql_projectId_project_projectId_fk";
--> statement-breakpoint
ALTER TABLE "postgres" DROP CONSTRAINT "postgres_projectId_project_projectId_fk";
--> statement-breakpoint
ALTER TABLE "redis" DROP CONSTRAINT "redis_projectId_project_projectId_fk";
--> statement-breakpoint
-- ALTER TABLE "mysql" ADD COLUMN "environmentId" text NOT NULL;--> statement-breakpoint
-- ALTER TABLE "mysql" ADD CONSTRAINT "mysql_environmentId_environment_environmentId_fk" FOREIGN KEY ("environmentId") REFERENCES "public"."environment"("environmentId") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "application" DROP COLUMN "projectId";--> statement-breakpoint
ALTER TABLE "compose" DROP COLUMN "projectId";--> statement-breakpoint
ALTER TABLE "mariadb" DROP COLUMN "projectId";--> statement-breakpoint
ALTER TABLE "mongo" DROP COLUMN "projectId";--> statement-breakpoint
ALTER TABLE "mysql" DROP COLUMN "projectId";--> statement-breakpoint
ALTER TABLE "postgres" DROP COLUMN "projectId";--> statement-breakpoint
ALTER TABLE "redis" DROP COLUMN "projectId";
File diff suppressed because it is too large Load Diff
+7
View File
@@ -764,6 +764,13 @@
"when": 1756767917601, "when": 1756767917601,
"tag": "0108_keen_doctor_faustus", "tag": "0108_keen_doctor_faustus",
"breakpoints": true "breakpoints": true
},
{
"idx": 109,
"version": "7",
"when": 1756772290701,
"tag": "0109_clammy_kabuki",
"breakpoints": true
} }
] ]
} }
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -4,6 +4,7 @@ import {
createApplication, createApplication,
deleteAllMiddlewares, deleteAllMiddlewares,
findApplicationById, findApplicationById,
findEnvironmentById,
findGitProviderById, findGitProviderById,
findProjectById, findProjectById,
getApplicationStats, getApplicationStats,
@@ -63,10 +64,14 @@ export const applicationRouter = createTRPCRouter({
.input(apiCreateApplication) .input(apiCreateApplication)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
try { try {
// Get project from environment
const environment = await findEnvironmentById(input.environmentId);
const project = await findProjectById(environment.projectId);
if (ctx.user.role === "member") { if (ctx.user.role === "member") {
await checkServiceAccess( await checkServiceAccess(
ctx.user.id, ctx.user.id,
input.projectId, project.projectId,
ctx.session.activeOrganizationId, ctx.session.activeOrganizationId,
"create", "create",
); );
@@ -79,13 +84,14 @@ export const applicationRouter = createTRPCRouter({
}); });
} }
const project = await findProjectById(input.projectId);
if (project.organizationId !== ctx.session.activeOrganizationId) { if (project.organizationId !== ctx.session.activeOrganizationId) {
throw new TRPCError({ throw new TRPCError({
code: "UNAUTHORIZED", code: "UNAUTHORIZED",
message: "You are not authorized to access this project", message: "You are not authorized to access this project",
}); });
} }
console.log("newApplication", input);
const newApplication = await createApplication(input); const newApplication = await createApplication(input);
if (ctx.user.role === "member") { if (ctx.user.role === "member") {
@@ -97,6 +103,7 @@ export const applicationRouter = createTRPCRouter({
} }
return newApplication; return newApplication;
} catch (error: unknown) { } catch (error: unknown) {
console.log("error", error);
if (error instanceof TRPCError) { if (error instanceof TRPCError) {
throw error; throw error;
} }
+14 -6
View File
@@ -12,6 +12,7 @@ import {
deleteMount, deleteMount,
findComposeById, findComposeById,
findDomainsByComposeId, findDomainsByComposeId,
findEnvironmentById,
findGitProviderById, findGitProviderById,
findProjectById, findProjectById,
findServerById, findServerById,
@@ -64,10 +65,14 @@ export const composeRouter = createTRPCRouter({
.input(apiCreateCompose) .input(apiCreateCompose)
.mutation(async ({ ctx, input }) => { .mutation(async ({ ctx, input }) => {
try { try {
// Get project from environment
const environment = await findEnvironmentById(input.environmentId);
const project = await findProjectById(environment.projectId);
if (ctx.user.role === "member") { if (ctx.user.role === "member") {
await checkServiceAccess( await checkServiceAccess(
ctx.user.id, ctx.user.id,
input.projectId, project.projectId,
ctx.session.activeOrganizationId, ctx.session.activeOrganizationId,
"create", "create",
); );
@@ -79,14 +84,15 @@ export const composeRouter = createTRPCRouter({
message: "You need to use a server to create a compose", message: "You need to use a server to create a compose",
}); });
} }
const project = await findProjectById(input.projectId);
if (project.organizationId !== ctx.session.activeOrganizationId) { if (project.organizationId !== ctx.session.activeOrganizationId) {
throw new TRPCError({ throw new TRPCError({
code: "UNAUTHORIZED", code: "UNAUTHORIZED",
message: "You are not authorized to access this project", message: "You are not authorized to access this project",
}); });
} }
const newService = await createCompose(input); const newService = await createCompose({
...input,
});
if (ctx.user.role === "member") { if (ctx.user.role === "member") {
await addNewService( await addNewService(
@@ -462,17 +468,19 @@ export const composeRouter = createTRPCRouter({
deployTemplate: protectedProcedure deployTemplate: protectedProcedure
.input( .input(
z.object({ z.object({
projectId: z.string(), environmentId: z.string(),
serverId: z.string().optional(), serverId: z.string().optional(),
id: z.string(), id: z.string(),
baseUrl: z.string().optional(), baseUrl: z.string().optional(),
}), }),
) )
.mutation(async ({ ctx, input }) => { .mutation(async ({ ctx, input }) => {
const environment = await findEnvironmentById(input.environmentId);
if (ctx.user.role === "member") { if (ctx.user.role === "member") {
await checkServiceAccess( await checkServiceAccess(
ctx.user.id, ctx.user.id,
input.projectId, environment.projectId,
ctx.session.activeOrganizationId, ctx.session.activeOrganizationId,
"create", "create",
); );
@@ -490,7 +498,7 @@ export const composeRouter = createTRPCRouter({
const admin = await findUserById(ctx.user.ownerId); const admin = await findUserById(ctx.user.ownerId);
let serverIp = admin.serverIp || "127.0.0.1"; let serverIp = admin.serverIp || "127.0.0.1";
const project = await findProjectById(input.projectId); const project = await findProjectById(environment.projectId);
if (input.serverId) { if (input.serverId) {
const server = await findServerById(input.serverId); const server = await findServerById(input.serverId);
+9 -3
View File
@@ -6,6 +6,7 @@ import {
deployMariadb, deployMariadb,
findBackupsByDbId, findBackupsByDbId,
findMariadbById, findMariadbById,
findEnvironmentById,
findProjectById, findProjectById,
IS_CLOUD, IS_CLOUD,
rebuildDatabase, rebuildDatabase,
@@ -41,10 +42,14 @@ export const mariadbRouter = createTRPCRouter({
.input(apiCreateMariaDB) .input(apiCreateMariaDB)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
try { try {
// Get project from environment
const environment = await findEnvironmentById(input.environmentId);
const project = await findProjectById(environment.projectId);
if (ctx.user.role === "member") { if (ctx.user.role === "member") {
await checkServiceAccess( await checkServiceAccess(
ctx.user.id, ctx.user.id,
input.projectId, project.projectId,
ctx.session.activeOrganizationId, ctx.session.activeOrganizationId,
"create", "create",
); );
@@ -57,14 +62,15 @@ export const mariadbRouter = createTRPCRouter({
}); });
} }
const project = await findProjectById(input.projectId);
if (project.organizationId !== ctx.session.activeOrganizationId) { if (project.organizationId !== ctx.session.activeOrganizationId) {
throw new TRPCError({ throw new TRPCError({
code: "UNAUTHORIZED", code: "UNAUTHORIZED",
message: "You are not authorized to access this project", message: "You are not authorized to access this project",
}); });
} }
const newMariadb = await createMariadb(input); const newMariadb = await createMariadb({
...input,
});
if (ctx.user.role === "member") { if (ctx.user.role === "member") {
await addNewService( await addNewService(
ctx.user.id, ctx.user.id,
+9 -3
View File
@@ -6,6 +6,7 @@ import {
deployMongo, deployMongo,
findBackupsByDbId, findBackupsByDbId,
findMongoById, findMongoById,
findEnvironmentById,
findProjectById, findProjectById,
IS_CLOUD, IS_CLOUD,
rebuildDatabase, rebuildDatabase,
@@ -41,10 +42,14 @@ export const mongoRouter = createTRPCRouter({
.input(apiCreateMongo) .input(apiCreateMongo)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
try { try {
// Get project from environment
const environment = await findEnvironmentById(input.environmentId);
const project = await findProjectById(environment.projectId);
if (ctx.user.role === "member") { if (ctx.user.role === "member") {
await checkServiceAccess( await checkServiceAccess(
ctx.user.id, ctx.user.id,
input.projectId, project.projectId,
ctx.session.activeOrganizationId, ctx.session.activeOrganizationId,
"create", "create",
); );
@@ -57,14 +62,15 @@ export const mongoRouter = createTRPCRouter({
}); });
} }
const project = await findProjectById(input.projectId);
if (project.organizationId !== ctx.session.activeOrganizationId) { if (project.organizationId !== ctx.session.activeOrganizationId) {
throw new TRPCError({ throw new TRPCError({
code: "UNAUTHORIZED", code: "UNAUTHORIZED",
message: "You are not authorized to access this project", message: "You are not authorized to access this project",
}); });
} }
const newMongo = await createMongo(input); const newMongo = await createMongo({
...input,
});
if (ctx.user.role === "member") { if (ctx.user.role === "member") {
await addNewService( await addNewService(
ctx.user.id, ctx.user.id,
+10 -4
View File
@@ -5,6 +5,7 @@ import {
createMysql, createMysql,
deployMySql, deployMySql,
findBackupsByDbId, findBackupsByDbId,
findEnvironmentById,
findMySqlById, findMySqlById,
findProjectById, findProjectById,
IS_CLOUD, IS_CLOUD,
@@ -42,10 +43,14 @@ export const mysqlRouter = createTRPCRouter({
.input(apiCreateMySql) .input(apiCreateMySql)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
try { try {
// Get project from environment
const environment = await findEnvironmentById(input.environmentId);
const project = await findProjectById(environment.projectId);
if (ctx.user.role === "member") { if (ctx.user.role === "member") {
await checkServiceAccess( await checkServiceAccess(
ctx.user.id, ctx.user.id,
input.projectId, project.projectId,
ctx.session.activeOrganizationId, ctx.session.activeOrganizationId,
"create", "create",
); );
@@ -57,8 +62,7 @@ export const mysqlRouter = createTRPCRouter({
message: "You need to use a server to create a MySQL", message: "You need to use a server to create a MySQL",
}); });
} }
1;
const project = await findProjectById(input.projectId);
if (project.organizationId !== ctx.session.activeOrganizationId) { if (project.organizationId !== ctx.session.activeOrganizationId) {
throw new TRPCError({ throw new TRPCError({
code: "UNAUTHORIZED", code: "UNAUTHORIZED",
@@ -66,7 +70,9 @@ export const mysqlRouter = createTRPCRouter({
}); });
} }
const newMysql = await createMysql(input); const newMysql = await createMysql({
...input,
});
if (ctx.user.role === "member") { if (ctx.user.role === "member") {
await addNewService( await addNewService(
ctx.user.id, ctx.user.id,
+9 -3
View File
@@ -5,6 +5,7 @@ import {
createPostgres, createPostgres,
deployPostgres, deployPostgres,
findBackupsByDbId, findBackupsByDbId,
findEnvironmentById,
findPostgresById, findPostgresById,
findProjectById, findProjectById,
IS_CLOUD, IS_CLOUD,
@@ -41,10 +42,14 @@ export const postgresRouter = createTRPCRouter({
.input(apiCreatePostgres) .input(apiCreatePostgres)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
try { try {
// Get project from environment
const environment = await findEnvironmentById(input.environmentId);
const project = await findProjectById(environment.projectId);
if (ctx.user.role === "member") { if (ctx.user.role === "member") {
await checkServiceAccess( await checkServiceAccess(
ctx.user.id, ctx.user.id,
input.projectId, project.projectId,
ctx.session.activeOrganizationId, ctx.session.activeOrganizationId,
"create", "create",
); );
@@ -57,14 +62,15 @@ export const postgresRouter = createTRPCRouter({
}); });
} }
const project = await findProjectById(input.projectId);
if (project.organizationId !== ctx.session.activeOrganizationId) { if (project.organizationId !== ctx.session.activeOrganizationId) {
throw new TRPCError({ throw new TRPCError({
code: "UNAUTHORIZED", code: "UNAUTHORIZED",
message: "You are not authorized to access this project", message: "You are not authorized to access this project",
}); });
} }
const newPostgres = await createPostgres(input); const newPostgres = await createPostgres({
...input,
});
if (ctx.user.role === "member") { if (ctx.user.role === "member") {
await addNewService( await addNewService(
ctx.user.id, ctx.user.id,
+9 -3
View File
@@ -4,6 +4,7 @@ import {
createMount, createMount,
createRedis, createRedis,
deployRedis, deployRedis,
findEnvironmentById,
findProjectById, findProjectById,
findRedisById, findRedisById,
IS_CLOUD, IS_CLOUD,
@@ -40,10 +41,14 @@ export const redisRouter = createTRPCRouter({
.input(apiCreateRedis) .input(apiCreateRedis)
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
try { try {
// Get project from environment
const environment = await findEnvironmentById(input.environmentId);
const project = await findProjectById(environment.projectId);
if (ctx.user.role === "member") { if (ctx.user.role === "member") {
await checkServiceAccess( await checkServiceAccess(
ctx.user.id, ctx.user.id,
input.projectId, project.projectId,
ctx.session.activeOrganizationId, ctx.session.activeOrganizationId,
"create", "create",
); );
@@ -56,14 +61,15 @@ export const redisRouter = createTRPCRouter({
}); });
} }
const project = await findProjectById(input.projectId);
if (project.organizationId !== ctx.session.activeOrganizationId) { if (project.organizationId !== ctx.session.activeOrganizationId) {
throw new TRPCError({ throw new TRPCError({
code: "UNAUTHORIZED", code: "UNAUTHORIZED",
message: "You are not authorized to access this project", message: "You are not authorized to access this project",
}); });
} }
const newRedis = await createRedis(input); const newRedis = await createRedis({
...input,
});
if (ctx.user.role === "member") { if (ctx.user.role === "member") {
await addNewService( await addNewService(
ctx.user.id, ctx.user.id,
+1 -9
View File
@@ -180,9 +180,6 @@ export const applications = pgTable("application", {
registryId: text("registryId").references(() => registry.registryId, { registryId: text("registryId").references(() => registry.registryId, {
onDelete: "set null", onDelete: "set null",
}), }),
projectId: text("projectId")
.notNull()
.references(() => projects.projectId, { onDelete: "cascade" }),
environmentId: text("environmentId") environmentId: text("environmentId")
.notNull() .notNull()
.references(() => environments.environmentId, { onDelete: "cascade" }), .references(() => environments.environmentId, { onDelete: "cascade" }),
@@ -206,10 +203,7 @@ export const applications = pgTable("application", {
export const applicationsRelations = relations( export const applicationsRelations = relations(
applications, applications,
({ one, many }) => ({ ({ one, many }) => ({
project: one(projects, {
fields: [applications.projectId],
references: [projects.projectId],
}),
environment: one(environments, { environment: one(environments, {
fields: [applications.environmentId], fields: [applications.environmentId],
references: [environments.environmentId], references: [environments.environmentId],
@@ -281,7 +275,6 @@ const createSchema = createInsertSchema(applications, {
customGitBuildPath: z.string().optional(), customGitBuildPath: z.string().optional(),
customGitUrl: z.string().optional(), customGitUrl: z.string().optional(),
buildPath: z.string().optional(), buildPath: z.string().optional(),
projectId: z.string(),
environmentId: z.string(), environmentId: z.string(),
sourceType: z sourceType: z
.enum(["github", "docker", "git", "gitlab", "bitbucket", "gitea", "drop"]) .enum(["github", "docker", "git", "gitlab", "bitbucket", "gitea", "drop"])
@@ -326,7 +319,6 @@ export const apiCreateApplication = createSchema.pick({
name: true, name: true,
appName: true, appName: true,
description: true, description: true,
projectId: true,
environmentId: true, environmentId: true,
serverId: true, serverId: true,
}); });
+1 -10
View File
@@ -85,9 +85,6 @@ export const compose = pgTable("compose", {
.default(false), .default(false),
triggerType: triggerType("triggerType").default("push"), triggerType: triggerType("triggerType").default("push"),
composeStatus: applicationStatus("composeStatus").notNull().default("idle"), composeStatus: applicationStatus("composeStatus").notNull().default("idle"),
projectId: text("projectId")
.notNull()
.references(() => projects.projectId, { onDelete: "cascade" }),
environmentId: text("environmentId") environmentId: text("environmentId")
.notNull() .notNull()
.references(() => environments.environmentId, { onDelete: "cascade" }), .references(() => environments.environmentId, { onDelete: "cascade" }),
@@ -113,10 +110,7 @@ export const compose = pgTable("compose", {
}); });
export const composeRelations = relations(compose, ({ one, many }) => ({ export const composeRelations = relations(compose, ({ one, many }) => ({
project: one(projects, {
fields: [compose.projectId],
references: [projects.projectId],
}),
environment: one(environments, { environment: one(environments, {
fields: [compose.environmentId], fields: [compose.environmentId],
references: [environments.environmentId], references: [environments.environmentId],
@@ -157,7 +151,6 @@ const createSchema = createInsertSchema(compose, {
description: z.string(), description: z.string(),
env: z.string().optional(), env: z.string().optional(),
composeFile: z.string().optional(), composeFile: z.string().optional(),
projectId: z.string(),
environmentId: z.string(), environmentId: z.string(),
customGitSSHKeyId: z.string().optional(), customGitSSHKeyId: z.string().optional(),
command: z.string().optional(), command: z.string().optional(),
@@ -169,7 +162,6 @@ const createSchema = createInsertSchema(compose, {
export const apiCreateCompose = createSchema.pick({ export const apiCreateCompose = createSchema.pick({
name: true, name: true,
description: true, description: true,
projectId: true,
environmentId: true, environmentId: true,
composeType: true, composeType: true,
appName: true, appName: true,
@@ -179,7 +171,6 @@ export const apiCreateCompose = createSchema.pick({
export const apiCreateComposeByTemplate = createSchema export const apiCreateComposeByTemplate = createSchema
.pick({ .pick({
projectId: true,
environmentId: true, environmentId: true,
}) })
.extend({ .extend({
+2 -9
View File
@@ -67,9 +67,7 @@ export const mariadb = pgTable("mariadb", {
createdAt: text("createdAt") createdAt: text("createdAt")
.notNull() .notNull()
.$defaultFn(() => new Date().toISOString()), .$defaultFn(() => new Date().toISOString()),
projectId: text("projectId")
.notNull()
.references(() => projects.projectId, { onDelete: "cascade" }),
environmentId: text("environmentId") environmentId: text("environmentId")
.notNull() .notNull()
.references(() => environments.environmentId, { onDelete: "cascade" }), .references(() => environments.environmentId, { onDelete: "cascade" }),
@@ -79,10 +77,7 @@ export const mariadb = pgTable("mariadb", {
}); });
export const mariadbRelations = relations(mariadb, ({ one, many }) => ({ export const mariadbRelations = relations(mariadb, ({ one, many }) => ({
project: one(projects, {
fields: [mariadb.projectId],
references: [projects.projectId],
}),
environment: one(environments, { environment: one(environments, {
fields: [mariadb.environmentId], fields: [mariadb.environmentId],
references: [environments.environmentId], references: [environments.environmentId],
@@ -123,7 +118,6 @@ const createSchema = createInsertSchema(mariadb, {
memoryLimit: z.string().optional(), memoryLimit: z.string().optional(),
cpuReservation: z.string().optional(), cpuReservation: z.string().optional(),
cpuLimit: z.string().optional(), cpuLimit: z.string().optional(),
projectId: z.string(),
environmentId: z.string(), environmentId: z.string(),
applicationStatus: z.enum(["idle", "running", "done", "error"]), applicationStatus: z.enum(["idle", "running", "done", "error"]),
externalPort: z.number(), externalPort: z.number(),
@@ -145,7 +139,6 @@ export const apiCreateMariaDB = createSchema
appName: true, appName: true,
dockerImage: true, dockerImage: true,
databaseRootPassword: true, databaseRootPassword: true,
projectId: true,
environmentId: true, environmentId: true,
description: true, description: true,
databaseName: true, databaseName: true,
+2 -9
View File
@@ -63,9 +63,7 @@ export const mongo = pgTable("mongo", {
createdAt: text("createdAt") createdAt: text("createdAt")
.notNull() .notNull()
.$defaultFn(() => new Date().toISOString()), .$defaultFn(() => new Date().toISOString()),
projectId: text("projectId")
.notNull()
.references(() => projects.projectId, { onDelete: "cascade" }),
environmentId: text("environmentId") environmentId: text("environmentId")
.notNull() .notNull()
.references(() => environments.environmentId, { onDelete: "cascade" }), .references(() => environments.environmentId, { onDelete: "cascade" }),
@@ -76,10 +74,7 @@ export const mongo = pgTable("mongo", {
}); });
export const mongoRelations = relations(mongo, ({ one, many }) => ({ export const mongoRelations = relations(mongo, ({ one, many }) => ({
project: one(projects, {
fields: [mongo.projectId],
references: [projects.projectId],
}),
environment: one(environments, { environment: one(environments, {
fields: [mongo.environmentId], fields: [mongo.environmentId],
references: [environments.environmentId], references: [environments.environmentId],
@@ -112,7 +107,6 @@ const createSchema = createInsertSchema(mongo, {
memoryLimit: z.string().optional(), memoryLimit: z.string().optional(),
cpuReservation: z.string().optional(), cpuReservation: z.string().optional(),
cpuLimit: z.string().optional(), cpuLimit: z.string().optional(),
projectId: z.string(),
environmentId: z.string(), environmentId: z.string(),
applicationStatus: z.enum(["idle", "running", "done", "error"]), applicationStatus: z.enum(["idle", "running", "done", "error"]),
externalPort: z.number(), externalPort: z.number(),
@@ -134,7 +128,6 @@ export const apiCreateMongo = createSchema
name: true, name: true,
appName: true, appName: true,
dockerImage: true, dockerImage: true,
projectId: true,
environmentId: true, environmentId: true,
description: true, description: true,
databaseUser: true, databaseUser: true,
+2 -9
View File
@@ -65,9 +65,7 @@ export const mysql = pgTable("mysql", {
createdAt: text("createdAt") createdAt: text("createdAt")
.notNull() .notNull()
.$defaultFn(() => new Date().toISOString()), .$defaultFn(() => new Date().toISOString()),
projectId: text("projectId")
.notNull()
.references(() => projects.projectId, { onDelete: "cascade" }),
environmentId: text("environmentId") environmentId: text("environmentId")
.notNull() .notNull()
.references(() => environments.environmentId, { onDelete: "cascade" }), .references(() => environments.environmentId, { onDelete: "cascade" }),
@@ -77,10 +75,7 @@ export const mysql = pgTable("mysql", {
}); });
export const mysqlRelations = relations(mysql, ({ one, many }) => ({ export const mysqlRelations = relations(mysql, ({ one, many }) => ({
project: one(projects, {
fields: [mysql.projectId],
references: [projects.projectId],
}),
environment: one(environments, { environment: one(environments, {
fields: [mysql.environmentId], fields: [mysql.environmentId],
references: [environments.environmentId], references: [environments.environmentId],
@@ -121,7 +116,6 @@ const createSchema = createInsertSchema(mysql, {
memoryLimit: z.string().optional(), memoryLimit: z.string().optional(),
cpuReservation: z.string().optional(), cpuReservation: z.string().optional(),
cpuLimit: z.string().optional(), cpuLimit: z.string().optional(),
projectId: z.string(),
applicationStatus: z.enum(["idle", "running", "done", "error"]), applicationStatus: z.enum(["idle", "running", "done", "error"]),
externalPort: z.number(), externalPort: z.number(),
description: z.string().optional(), description: z.string().optional(),
@@ -141,7 +135,6 @@ export const apiCreateMySql = createSchema
name: true, name: true,
appName: true, appName: true,
dockerImage: true, dockerImage: true,
projectId: true,
environmentId: true, environmentId: true,
description: true, description: true,
databaseName: true, databaseName: true,
+2 -9
View File
@@ -65,9 +65,7 @@ export const postgres = pgTable("postgres", {
createdAt: text("createdAt") createdAt: text("createdAt")
.notNull() .notNull()
.$defaultFn(() => new Date().toISOString()), .$defaultFn(() => new Date().toISOString()),
projectId: text("projectId")
.notNull()
.references(() => projects.projectId, { onDelete: "cascade" }),
environmentId: text("environmentId") environmentId: text("environmentId")
.notNull() .notNull()
.references(() => environments.environmentId, { onDelete: "cascade" }), .references(() => environments.environmentId, { onDelete: "cascade" }),
@@ -77,10 +75,7 @@ export const postgres = pgTable("postgres", {
}); });
export const postgresRelations = relations(postgres, ({ one, many }) => ({ export const postgresRelations = relations(postgres, ({ one, many }) => ({
project: one(projects, {
fields: [postgres.projectId],
references: [projects.projectId],
}),
environment: one(environments, { environment: one(environments, {
fields: [postgres.environmentId], fields: [postgres.environmentId],
references: [environments.environmentId], references: [environments.environmentId],
@@ -112,7 +107,6 @@ const createSchema = createInsertSchema(postgres, {
memoryLimit: z.string().optional(), memoryLimit: z.string().optional(),
cpuReservation: z.string().optional(), cpuReservation: z.string().optional(),
cpuLimit: z.string().optional(), cpuLimit: z.string().optional(),
projectId: z.string(),
environmentId: z.string(), environmentId: z.string(),
applicationStatus: z.enum(["idle", "running", "done", "error"]), applicationStatus: z.enum(["idle", "running", "done", "error"]),
externalPort: z.number(), externalPort: z.number(),
@@ -137,7 +131,6 @@ export const apiCreatePostgres = createSchema
databaseUser: true, databaseUser: true,
databasePassword: true, databasePassword: true,
dockerImage: true, dockerImage: true,
projectId: true,
environmentId: true, environmentId: true,
description: true, description: true,
serverId: true, serverId: true,
+2 -9
View File
@@ -61,9 +61,7 @@ export const redis = pgTable("redis", {
labelsSwarm: json("labelsSwarm").$type<LabelsSwarm>(), labelsSwarm: json("labelsSwarm").$type<LabelsSwarm>(),
networkSwarm: json("networkSwarm").$type<NetworkSwarm[]>(), networkSwarm: json("networkSwarm").$type<NetworkSwarm[]>(),
replicas: integer("replicas").default(1).notNull(), replicas: integer("replicas").default(1).notNull(),
projectId: text("projectId")
.notNull()
.references(() => projects.projectId, { onDelete: "cascade" }),
environmentId: text("environmentId") environmentId: text("environmentId")
.notNull() .notNull()
.references(() => environments.environmentId, { onDelete: "cascade" }), .references(() => environments.environmentId, { onDelete: "cascade" }),
@@ -73,10 +71,7 @@ export const redis = pgTable("redis", {
}); });
export const redisRelations = relations(redis, ({ one, many }) => ({ export const redisRelations = relations(redis, ({ one, many }) => ({
project: one(projects, {
fields: [redis.projectId],
references: [projects.projectId],
}),
environment: one(environments, { environment: one(environments, {
fields: [redis.environmentId], fields: [redis.environmentId],
references: [environments.environmentId], references: [environments.environmentId],
@@ -101,7 +96,6 @@ const createSchema = createInsertSchema(redis, {
memoryLimit: z.string().optional(), memoryLimit: z.string().optional(),
cpuReservation: z.string().optional(), cpuReservation: z.string().optional(),
cpuLimit: z.string().optional(), cpuLimit: z.string().optional(),
projectId: z.string(),
environmentId: z.string(), environmentId: z.string(),
applicationStatus: z.enum(["idle", "running", "done", "error"]), applicationStatus: z.enum(["idle", "running", "done", "error"]),
externalPort: z.number(), externalPort: z.number(),
@@ -123,7 +117,6 @@ export const apiCreateRedis = createSchema
appName: true, appName: true,
databasePassword: true, databasePassword: true,
dockerImage: true, dockerImage: true,
projectId: true,
environmentId: true, environmentId: true,
description: true, description: true,
serverId: true, serverId: true,
+4 -1
View File
@@ -76,6 +76,7 @@ export const createApplication = async (
}); });
} }
console.log("input", input);
return await db.transaction(async (tx) => { return await db.transaction(async (tx) => {
const newApplication = await tx const newApplication = await tx
.insert(applications) .insert(applications)
@@ -86,6 +87,8 @@ export const createApplication = async (
.returning() .returning()
.then((value) => value[0]); .then((value) => value[0]);
console.log("newApplication", newApplication);
if (!newApplication) { if (!newApplication) {
throw new TRPCError({ throw new TRPCError({
code: "BAD_REQUEST", code: "BAD_REQUEST",
@@ -105,7 +108,7 @@ export const findApplicationById = async (applicationId: string) => {
const application = await db.query.applications.findFirst({ const application = await db.query.applications.findFirst({
where: eq(applications.applicationId, applicationId), where: eq(applications.applicationId, applicationId),
with: { with: {
project: true, environment: true,
domains: true, domains: true,
deployments: true, deployments: true,
mounts: true, mounts: true,
@@ -33,6 +33,16 @@ export const createEnvironment = async (
export const findEnvironmentById = async (environmentId: string) => { export const findEnvironmentById = async (environmentId: string) => {
const environment = await db.query.environments.findFirst({ const environment = await db.query.environments.findFirst({
where: eq(environments.environmentId, environmentId), where: eq(environments.environmentId, environmentId),
with: {
applications: true,
mariadb: true,
mongo: true,
mysql: true,
postgres: true,
redis: true,
compose: true,
project: true,
},
}); });
if (!environment) { if (!environment) {
throw new TRPCError({ throw new TRPCError({
+1 -1
View File
@@ -99,7 +99,7 @@ export const updateProjectById = async (
}; };
export const validUniqueServerAppName = async (appName: string) => { export const validUniqueServerAppName = async (appName: string) => {
const query = await db.query.projects.findMany({ const query = await db.query.environments.findMany({
with: { with: {
applications: { applications: {
where: eq(applications.appName, appName), where: eq(applications.appName, appName),