mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
changing restauration to restoration.
This commit is contained in:
@@ -30,11 +30,11 @@ export default async function RoutePage(props: PageParams<{ databaseId: string }
|
|||||||
databaseId: database.id
|
databaseId: database.id
|
||||||
},
|
},
|
||||||
include:{
|
include:{
|
||||||
restaurations: {}
|
restorations: {}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const restaurations = await prisma.restauration.findMany({
|
const restorations = await prisma.restoration.findMany({
|
||||||
where: {
|
where: {
|
||||||
databaseId: databaseId,
|
databaseId: databaseId,
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ export default async function RoutePage(props: PageParams<{ databaseId: string }
|
|||||||
|
|
||||||
|
|
||||||
const isAlreadyBackup = !!backups.find(backup => backup.status === "waiting");
|
const isAlreadyBackup = !!backups.find(backup => backup.status === "waiting");
|
||||||
const isAlreadyRestore = !!restaurations.find(restoration => restoration.status === "waiting");
|
const isAlreadyRestore = !!restorations.find(restoration => restoration.status === "waiting");
|
||||||
|
|
||||||
const totalBackups = await prisma.backup.count({
|
const totalBackups = await prisma.backup.count({
|
||||||
where: {
|
where: {
|
||||||
@@ -79,7 +79,7 @@ export default async function RoutePage(props: PageParams<{ databaseId: string }
|
|||||||
<DatabaseTabs
|
<DatabaseTabs
|
||||||
isAlreadyRestore={isAlreadyRestore}
|
isAlreadyRestore={isAlreadyRestore}
|
||||||
backups={backups}
|
backups={backups}
|
||||||
restaurations={restaurations}
|
restorations={restorations}
|
||||||
/>
|
/>
|
||||||
</PageContent>
|
</PageContent>
|
||||||
</Page>
|
</Page>
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export async function POST(
|
|||||||
return NextResponse.json({error: "Database associated with generatedId provided not found"}, {status: 404})
|
return NextResponse.json({error: "Database associated with generatedId provided not found"}, {status: 404})
|
||||||
}
|
}
|
||||||
|
|
||||||
const restoration = await prisma.restauration.findFirst({
|
const restoration = await prisma.restoration.findFirst({
|
||||||
where: {
|
where: {
|
||||||
status : "ongoing",
|
status : "ongoing",
|
||||||
databaseId: database.id
|
databaseId: database.id
|
||||||
@@ -59,7 +59,7 @@ export async function POST(
|
|||||||
return NextResponse.json({error: "Unable to fin the corresponding restoration"}, {status: 404})
|
return NextResponse.json({error: "Unable to fin the corresponding restoration"}, {status: 404})
|
||||||
}
|
}
|
||||||
|
|
||||||
await prisma.restauration.update({
|
await prisma.restoration.update({
|
||||||
where:{
|
where:{
|
||||||
id : restoration.id
|
id : restoration.id
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ export async function handleDatabases(body: Body, agent: Agent, lastContact: Dat
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const restoration = await prisma.restauration.findFirst({
|
const restoration = await prisma.restoration.findFirst({
|
||||||
where:{
|
where:{
|
||||||
databaseId: databaseUpdated.id,
|
databaseId: databaseUpdated.id,
|
||||||
status: "waiting"
|
status: "waiting"
|
||||||
@@ -108,7 +108,7 @@ export async function handleDatabases(body: Body, agent: Agent, lastContact: Dat
|
|||||||
})
|
})
|
||||||
const fileName = backupToRestore.file
|
const fileName = backupToRestore.file
|
||||||
UrlBackup = await getFileUrlPresignedLocal(fileName)
|
UrlBackup = await getFileUrlPresignedLocal(fileName)
|
||||||
await prisma.restauration.update({
|
await prisma.restoration.update({
|
||||||
where: {
|
where: {
|
||||||
id: restoration.id
|
id: restoration.id
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- You are about to drop the `restaurations` table. If the table is not empty, all the data it contains will be lost.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- DropForeignKey
|
||||||
|
ALTER TABLE "restaurations" DROP CONSTRAINT "restaurations_backup_id_fkey";
|
||||||
|
|
||||||
|
-- DropForeignKey
|
||||||
|
ALTER TABLE "restaurations" DROP CONSTRAINT "restaurations_database_id_fkey";
|
||||||
|
|
||||||
|
-- DropTable
|
||||||
|
DROP TABLE "restaurations";
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "restorations" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"status" "Status" NOT NULL DEFAULT 'waiting',
|
||||||
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"backup_id" TEXT NOT NULL,
|
||||||
|
"database_id" TEXT,
|
||||||
|
|
||||||
|
CONSTRAINT "restorations_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "restorations" ADD CONSTRAINT "restorations_backup_id_fkey" FOREIGN KEY ("backup_id") REFERENCES "backups"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "restorations" ADD CONSTRAINT "restorations_database_id_fkey" FOREIGN KEY ("database_id") REFERENCES "databases"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
@@ -150,7 +150,7 @@ model Database {
|
|||||||
lastContact DateTime? @map("last_contact")
|
lastContact DateTime? @map("last_contact")
|
||||||
|
|
||||||
backups Backup[]
|
backups Backup[]
|
||||||
restaurations Restauration[]
|
restorations Restoration[]
|
||||||
|
|
||||||
projectId String? @map("project_id")
|
projectId String? @map("project_id")
|
||||||
project Project? @relation(fields: [projectId], references: [id])
|
project Project? @relation(fields: [projectId], references: [id])
|
||||||
@@ -174,12 +174,12 @@ model Backup {
|
|||||||
databaseId String @map("database_id")
|
databaseId String @map("database_id")
|
||||||
database Database @relation(fields: [databaseId], references: [id], onDelete: Cascade)
|
database Database @relation(fields: [databaseId], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
restaurations Restauration[]
|
restorations Restoration[]
|
||||||
|
|
||||||
@@map("backups")
|
@@map("backups")
|
||||||
}
|
}
|
||||||
|
|
||||||
model Restauration {
|
model Restoration {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
status Status @default(waiting)
|
status Status @default(waiting)
|
||||||
createdAt DateTime @default(now()) @map("created_at")
|
createdAt DateTime @default(now()) @map("created_at")
|
||||||
@@ -190,7 +190,7 @@ model Restauration {
|
|||||||
databaseId String? @map("database_id")
|
databaseId String? @map("database_id")
|
||||||
database Database? @relation(fields: [databaseId], references: [id], onDelete: Cascade)
|
database Database? @relation(fields: [databaseId], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
@@map("restaurations")
|
@@map("restorations")
|
||||||
}
|
}
|
||||||
|
|
||||||
enum TypeStorage {
|
enum TypeStorage {
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ import {Tabs, TabsContent, TabsList, TabsTrigger} from "@/components/ui/tabs";
|
|||||||
import {DataTableWithPagination} from "@/components/wrappers/table/data-table-with-pagination";
|
import {DataTableWithPagination} from "@/components/wrappers/table/data-table-with-pagination";
|
||||||
import {backupColumns} from "@/features/backup/columns";
|
import {backupColumns} from "@/features/backup/columns";
|
||||||
import {restoreColumns} from "@/features/restore/columns";
|
import {restoreColumns} from "@/features/restore/columns";
|
||||||
import {Backup, Restauration} from "@prisma/client";
|
import {Backup, Restoration} from "@prisma/client";
|
||||||
|
|
||||||
export type DatabaseTabsProps = {
|
export type DatabaseTabsProps = {
|
||||||
backups: Backup[]
|
backups: Backup[]
|
||||||
restaurations: Restauration[]
|
restorations: Restoration[]
|
||||||
isAlreadyRestore: boolean
|
isAlreadyRestore: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ export const DatabaseTabs = (props: DatabaseTabsProps) => {
|
|||||||
</TabsContent>
|
</TabsContent>
|
||||||
|
|
||||||
<TabsContent className="h-full justify-between" value="restore">
|
<TabsContent className="h-full justify-between" value="restore">
|
||||||
<DataTableWithPagination columns={restoreColumns} data={props.restaurations}/>
|
<DataTableWithPagination columns={restoreColumns} data={props.restorations}/>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -36,8 +36,6 @@ export const DatabaseForm = (props: DatabaseFormProps) => {
|
|||||||
defaultValues: {...defaultValues},
|
defaultValues: {...defaultValues},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("aaaaaaaaaa", form.getValues())
|
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const mutation = useMutation({
|
const mutation = useMutation({
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {ReloadIcon} from "@radix-ui/react-icons";
|
|||||||
import {Backup} from "@prisma/client";
|
import {Backup} from "@prisma/client";
|
||||||
import {getFileUrlPresignedLocal} from "@/features/upload/private/upload.action";
|
import {getFileUrlPresignedLocal} from "@/features/upload/private/upload.action";
|
||||||
import {useMutation} from "@tanstack/react-query";
|
import {useMutation} from "@tanstack/react-query";
|
||||||
import {createRestaurationAction} from "@/features/restore/restore.action";
|
import {createRestorationAction} from "@/features/restore/restore.action";
|
||||||
import {toast} from "sonner";
|
import {toast} from "sonner";
|
||||||
import {useRouter} from "next/navigation";
|
import {useRouter} from "next/navigation";
|
||||||
import {TooltipCustom} from "@/components/wrappers/TooltipCustom/TooltipCustom";
|
import {TooltipCustom} from "@/components/wrappers/TooltipCustom/TooltipCustom";
|
||||||
@@ -50,7 +50,7 @@ export const backupColumns: ColumnDef<Backup>[] = [
|
|||||||
const {extendedProps} = table.options.meta;
|
const {extendedProps} = table.options.meta;
|
||||||
|
|
||||||
|
|
||||||
// const isRestauring = !!rowData.restaurations.find(restauration => restauration.status === "waiting");
|
// const isRestoring = !!rowData.restorations.find(restoration => restoration.status === "waiting");
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
@@ -62,15 +62,15 @@ export const backupColumns: ColumnDef<Backup>[] = [
|
|||||||
|
|
||||||
const mutationRestore = useMutation({
|
const mutationRestore = useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
const restauration = await createRestaurationAction({
|
const restoration = await createRestorationAction({
|
||||||
backupId: rowData.id,
|
backupId: rowData.id,
|
||||||
databaseId: rowData.databaseId
|
databaseId: rowData.databaseId
|
||||||
})
|
})
|
||||||
if (restauration.data.success) {
|
if (restoration.data.success) {
|
||||||
toast.success(restauration.data.actionSuccess?.message || "Restauration created successfully!");
|
toast.success(restoration.data.actionSuccess?.message || "Restoration created successfully!");
|
||||||
router.refresh()
|
router.refresh()
|
||||||
} else {
|
} else {
|
||||||
toast.error(restauration.serverError || "Failed to create restauration.");
|
toast.error(restoration.serverError || "Failed to create restoration.");
|
||||||
}
|
}
|
||||||
}})
|
}})
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ export const backupColumns: ColumnDef<Backup>[] = [
|
|||||||
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
||||||
{status == "success" ?
|
{status == "success" ?
|
||||||
<>
|
<>
|
||||||
<TooltipCustom disabled={extendedProps} text="Already a restauration waiting">
|
<TooltipCustom disabled={extendedProps} text="Already a restoration waiting">
|
||||||
<DropdownMenuItem disabled={mutationRestore.isPending || extendedProps}
|
<DropdownMenuItem disabled={mutationRestore.isPending || extendedProps}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
await handleRestore()
|
await handleRestore()
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ import {
|
|||||||
import {Button} from "@/components/ui/button";
|
import {Button} from "@/components/ui/button";
|
||||||
import {Download, MoreHorizontal, Trash2} from "lucide-react";
|
import {Download, MoreHorizontal, Trash2} from "lucide-react";
|
||||||
import {ReloadIcon} from "@radix-ui/react-icons";
|
import {ReloadIcon} from "@radix-ui/react-icons";
|
||||||
import {Restauration} from "@prisma/client";
|
import {Restoration} from "@prisma/client";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const restoreColumns: ColumnDef<Restauration>[] = [
|
export const restoreColumns: ColumnDef<Restoration>[] = [
|
||||||
{
|
{
|
||||||
accessorKey: "id",
|
accessorKey: "id",
|
||||||
header: "Reference",
|
header: "Reference",
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
"use server"
|
"use server"
|
||||||
|
|
||||||
import {userAction} from "@/safe-actions";
|
import {userAction} from "@/safe-actions";
|
||||||
import {z} from "zod";
|
import {z} from "zod";
|
||||||
import {prisma} from "@/prisma";
|
import {prisma} from "@/prisma";
|
||||||
import {ServerActionResult} from "@/types/action-type";
|
import {ServerActionResult} from "@/types/action-type";
|
||||||
import {Restauration} from "@prisma/client";
|
import {Restoration} from "@prisma/client";
|
||||||
|
|
||||||
|
|
||||||
export const createRestaurationAction = userAction
|
export const createRestorationAction = userAction
|
||||||
.schema(z.object({
|
.schema(z.object({
|
||||||
backupId: z.string(),
|
backupId: z.string(),
|
||||||
databaseId: z.string(),
|
databaseId: z.string(),
|
||||||
}))
|
}))
|
||||||
.action(async ({parsedInput, ctx}): Promise<ServerActionResult<Restauration>> => {
|
.action(async ({parsedInput, ctx}): Promise<ServerActionResult<Restoration>> => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const restauration = await prisma.restauration.create({
|
const restoration = await prisma.restoration.create({
|
||||||
data: {
|
data: {
|
||||||
databaseId: parsedInput.databaseId,
|
databaseId: parsedInput.databaseId,
|
||||||
backupId: parsedInput.backupId,
|
backupId: parsedInput.backupId,
|
||||||
@@ -24,14 +25,14 @@ export const createRestaurationAction = userAction
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
value: restauration,
|
value: restoration,
|
||||||
actionSuccess: {
|
actionSuccess: {
|
||||||
message: "Restoration has been successfully created.",
|
message: "Restoration has been successfully created.",
|
||||||
messageParams: { restaurationId: restauration.id },
|
messageParams: { restorationId: restoration.id },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error creating restauration:", error);
|
console.error("Error creating restoration:", error);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
actionError: {
|
actionError: {
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export const databases = [
|
|||||||
"lastContact": "2024-11-28T08:30:00.000Z",
|
"lastContact": "2024-11-28T08:30:00.000Z",
|
||||||
"projectId": "proj-789",
|
"projectId": "proj-789",
|
||||||
"backups": [],
|
"backups": [],
|
||||||
"restaurations": []
|
"restorations": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "1e4f9265-5f10-4bd4-8e5c-3283746cfd7a",
|
"id": "1e4f9265-5f10-4bd4-8e5c-3283746cfd7a",
|
||||||
@@ -67,7 +67,7 @@ export const databases = [
|
|||||||
"lastContact": "2024-11-25T10:15:00.000Z",
|
"lastContact": "2024-11-25T10:15:00.000Z",
|
||||||
"projectId": null,
|
"projectId": null,
|
||||||
"backups": [],
|
"backups": [],
|
||||||
"restaurations": []
|
"restorations": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "b6f92bd7-834b-41c1-b6b3-dc4214b1de08",
|
"id": "b6f92bd7-834b-41c1-b6b3-dc4214b1de08",
|
||||||
@@ -81,7 +81,7 @@ export const databases = [
|
|||||||
"lastContact": null,
|
"lastContact": null,
|
||||||
"projectId": "proj-456",
|
"projectId": "proj-456",
|
||||||
"backups": [],
|
"backups": [],
|
||||||
"restaurations": []
|
"restorations": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ export const backups = [
|
|||||||
{'id': 'backup-11', 'createdAt': '2023-11-25T11:26:54.871000Z', 'status': 'failed'}
|
{'id': 'backup-11', 'createdAt': '2023-11-25T11:26:54.871000Z', 'status': 'failed'}
|
||||||
]
|
]
|
||||||
|
|
||||||
export const restaurations = [
|
export const restorations = [
|
||||||
{'id': 'restore-1', 'backupId': 'backup-1', 'createdAt': '2023-11-27T11:26:54.870914Z', 'status': 'pending'},
|
{'id': 'restore-1', 'backupId': 'backup-1', 'createdAt': '2023-11-27T11:26:54.870914Z', 'status': 'pending'},
|
||||||
{'id': 'restore-2', 'backupId': 'backup-2', 'createdAt': '2023-12-03T11:26:54.870927Z', 'status': 'failed'},
|
{'id': 'restore-2', 'backupId': 'backup-2', 'createdAt': '2023-12-03T11:26:54.870927Z', 'status': 'failed'},
|
||||||
{'id': 'restore-3', 'backupId': 'backup-3', 'createdAt': '2023-12-12T11:26:54.870937Z', 'status': 'success'},
|
{'id': 'restore-3', 'backupId': 'backup-3', 'createdAt': '2023-12-12T11:26:54.870937Z', 'status': 'success'},
|
||||||
|
|||||||
Reference in New Issue
Block a user