Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions apps/dokploy/components/dashboard/shared/rebuild-database.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AlertTriangle, DatabaseIcon } from "lucide-react";
import { useRouter } from "next/router";
import { toast } from "sonner";
import {
AlertDialog,
Expand All @@ -21,8 +22,19 @@ interface Props {
}

export const RebuildDatabase = ({ id, type }: Props) => {
const router = useRouter();
const utils = api.useUtils();

const goToBackups = () => {
const projectId = router.query.projectId as string;
const environmentId = router.query.environmentId as string;
router.push(
`/dashboard/project/${projectId}/environment/${environmentId}/services/${type}/${id}?tab=backups`,
undefined,
{ shallow: true },
);
};

const mutationMap = {
libsql: () => api.libsql.rebuild.useMutation(),
mariadb: () => api.mariadb.rebuild.useMutation(),
Expand Down Expand Up @@ -69,6 +81,19 @@ export const RebuildDatabase = ({ id, type }: Props) => {
This action will completely reset your database to its initial
state. All data, tables, and configurations will be removed.
</p>
<p className="text-sm text-amber-600 dark:text-amber-400 flex items-center gap-1.5">
<AlertTriangle className="h-3.5 w-3.5 shrink-0" />
<span>
<strong>Recommended:</strong>{" "}
<span
onClick={goToBackups}
className="underline underline-offset-2 hover:text-amber-500 cursor-pointer"
>
Create a backup
</span>{" "}
before rebuilding to avoid permanent data loss.
</span>
</p>
</div>
<AlertDialog>
<AlertDialogTrigger asChild>
Expand Down Expand Up @@ -99,6 +124,19 @@ export const RebuildDatabase = ({ id, type }: Props) => {
<p className="font-medium text-destructive mt-4">
This action cannot be undone.
</p>
<p className="text-sm text-amber-600 dark:text-amber-400 flex items-center gap-1.5 mt-2">
<AlertTriangle className="h-3.5 w-3.5 shrink-0" />
<span>
<strong>Tip:</strong>{" "}
<span
onClick={goToBackups}
className="underline underline-offset-2 hover:text-amber-500 cursor-pointer"
>
Go to the Backups tab
</span>{" "}
to create a backup before rebuilding.
</span>
</p>
</div>
</AlertDialogDescription>
</AlertDialogHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
import Head from "next/head";
import Link from "next/link";
import { useRouter } from "next/router";
import { type ReactElement, useState } from "react";
import { type ReactElement, useEffect, useState } from "react";
import { toast } from "sonner";
import superjson from "superjson";
import { ShowEnvironment } from "@/components/dashboard/application/environment/show-environment";
Expand Down Expand Up @@ -59,6 +59,12 @@ const Libsql = (
const router = useRouter();
const { projectId, environmentId } = router.query;
const [tab, setSab] = useState<TabState>(activeTab);
useEffect(() => {
const tabFromUrl = router.query.tab as TabState;
if (tabFromUrl && tabFromUrl !== tab) {
setSab(tabFromUrl);
}
}, [router.query.tab]);
const { data } = api.libsql.one.useQuery({ libsqlId });
const { data: auth } = api.user.get.useQuery();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
import Head from "next/head";
import Link from "next/link";
import { useRouter } from "next/router";
import { type ReactElement, useState } from "react";
import { type ReactElement, useEffect, useState } from "react";
import { toast } from "sonner";
import superjson from "superjson";
import { ShowEnvironment } from "@/components/dashboard/application/environment/show-environment";
Expand Down Expand Up @@ -60,6 +60,12 @@ const Mariadb = (
const router = useRouter();
const { projectId, environmentId } = router.query;
const [tab, setSab] = useState<TabState>(activeTab);
useEffect(() => {
const tabFromUrl = router.query.tab as TabState;
if (tabFromUrl && tabFromUrl !== tab) {
setSab(tabFromUrl);
}
}, [router.query.tab]);
const { data } = api.mariadb.one.useQuery({ mariadbId });
const { data: auth } = api.user.get.useQuery();
const { data: permissions } = api.user.getPermissions.useQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
import Head from "next/head";
import Link from "next/link";
import { useRouter } from "next/router";
import { type ReactElement, useState } from "react";
import { type ReactElement, useEffect, useState } from "react";
import { toast } from "sonner";
import superjson from "superjson";
import { ShowEnvironment } from "@/components/dashboard/application/environment/show-environment";
Expand Down Expand Up @@ -59,6 +59,12 @@ const Mongo = (
const router = useRouter();
const { projectId, environmentId } = router.query;
const [tab, setSab] = useState<TabState>(activeTab);
useEffect(() => {
const tabFromUrl = router.query.tab as TabState;
if (tabFromUrl && tabFromUrl !== tab) {
setSab(tabFromUrl);
}
}, [router.query.tab]);
const { data } = api.mongo.one.useQuery({ mongoId });

const { data: auth } = api.user.get.useQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
import Head from "next/head";
import Link from "next/link";
import { useRouter } from "next/router";
import { type ReactElement, useState } from "react";
import { type ReactElement, useEffect, useState } from "react";
import { toast } from "sonner";
import superjson from "superjson";
import { ShowEnvironment } from "@/components/dashboard/application/environment/show-environment";
Expand Down Expand Up @@ -59,6 +59,12 @@ const MySql = (
const router = useRouter();
const { projectId, environmentId } = router.query;
const [tab, setSab] = useState<TabState>(activeTab);
useEffect(() => {
const tabFromUrl = router.query.tab as TabState;
if (tabFromUrl && tabFromUrl !== tab) {
setSab(tabFromUrl);
}
}, [router.query.tab]);
const { data } = api.mysql.one.useQuery({ mysqlId });
const { data: auth } = api.user.get.useQuery();
const { data: permissions } = api.user.getPermissions.useQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
import Head from "next/head";
import Link from "next/link";
import { useRouter } from "next/router";
import { type ReactElement, useState } from "react";
import { type ReactElement, useEffect, useState } from "react";
import { toast } from "sonner";
import superjson from "superjson";
import { ShowEnvironment } from "@/components/dashboard/application/environment/show-environment";
Expand Down Expand Up @@ -59,6 +59,12 @@ const Postgresql = (
const router = useRouter();
const { projectId, environmentId } = router.query;
const [tab, setSab] = useState<TabState>(activeTab);
useEffect(() => {
const tabFromUrl = router.query.tab as TabState;
if (tabFromUrl && tabFromUrl !== tab) {
setSab(tabFromUrl);
}
}, [router.query.tab]);
const { data } = api.postgres.one.useQuery({ postgresId });
const { data: auth } = api.user.get.useQuery();
const { data: permissions } = api.user.getPermissions.useQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
import Head from "next/head";
import Link from "next/link";
import { useRouter } from "next/router";
import { type ReactElement, useState } from "react";
import { type ReactElement, useEffect, useState } from "react";
import { toast } from "sonner";
import superjson from "superjson";
import { ShowEnvironment } from "@/components/dashboard/application/environment/show-environment";
Expand Down Expand Up @@ -58,6 +58,12 @@ const Redis = (
const router = useRouter();
const { projectId, environmentId } = router.query;
const [tab, setSab] = useState<TabState>(activeTab);
useEffect(() => {
const tabFromUrl = router.query.tab as TabState;
if (tabFromUrl && tabFromUrl !== tab) {
setSab(tabFromUrl);
}
}, [router.query.tab]);
const { data } = api.redis.one.useQuery({ redisId });

const { data: auth } = api.user.get.useQuery();
Expand Down