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
|
||||
},
|
||||
include:{
|
||||
restaurations: {}
|
||||
restorations: {}
|
||||
}
|
||||
})
|
||||
|
||||
const restaurations = await prisma.restauration.findMany({
|
||||
const restorations = await prisma.restoration.findMany({
|
||||
where: {
|
||||
databaseId: databaseId,
|
||||
}
|
||||
@@ -42,7 +42,7 @@ export default async function RoutePage(props: PageParams<{ databaseId: string }
|
||||
|
||||
|
||||
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({
|
||||
where: {
|
||||
@@ -79,7 +79,7 @@ export default async function RoutePage(props: PageParams<{ databaseId: string }
|
||||
<DatabaseTabs
|
||||
isAlreadyRestore={isAlreadyRestore}
|
||||
backups={backups}
|
||||
restaurations={restaurations}
|
||||
restorations={restorations}
|
||||
/>
|
||||
</PageContent>
|
||||
</Page>
|
||||
|
||||
@@ -49,7 +49,7 @@ export async function POST(
|
||||
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: {
|
||||
status : "ongoing",
|
||||
databaseId: database.id
|
||||
@@ -59,7 +59,7 @@ export async function POST(
|
||||
return NextResponse.json({error: "Unable to fin the corresponding restoration"}, {status: 404})
|
||||
}
|
||||
|
||||
await prisma.restauration.update({
|
||||
await prisma.restoration.update({
|
||||
where:{
|
||||
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:{
|
||||
databaseId: databaseUpdated.id,
|
||||
status: "waiting"
|
||||
@@ -108,7 +108,7 @@ export async function handleDatabases(body: Body, agent: Agent, lastContact: Dat
|
||||
})
|
||||
const fileName = backupToRestore.file
|
||||
UrlBackup = await getFileUrlPresignedLocal(fileName)
|
||||
await prisma.restauration.update({
|
||||
await prisma.restoration.update({
|
||||
where: {
|
||||
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;
|
||||
@@ -149,8 +149,8 @@ model Database {
|
||||
agent Agent @relation(fields: [agentId], references: [id], onDelete: Cascade)
|
||||
lastContact DateTime? @map("last_contact")
|
||||
|
||||
backups Backup[]
|
||||
restaurations Restauration[]
|
||||
backups Backup[]
|
||||
restorations Restoration[]
|
||||
|
||||
projectId String? @map("project_id")
|
||||
project Project? @relation(fields: [projectId], references: [id])
|
||||
@@ -174,12 +174,12 @@ model Backup {
|
||||
databaseId String @map("database_id")
|
||||
database Database @relation(fields: [databaseId], references: [id], onDelete: Cascade)
|
||||
|
||||
restaurations Restauration[]
|
||||
restorations Restoration[]
|
||||
|
||||
@@map("backups")
|
||||
}
|
||||
|
||||
model Restauration {
|
||||
model Restoration {
|
||||
id String @id @default(cuid())
|
||||
status Status @default(waiting)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
@@ -190,7 +190,7 @@ model Restauration {
|
||||
databaseId String? @map("database_id")
|
||||
database Database? @relation(fields: [databaseId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@map("restaurations")
|
||||
@@map("restorations")
|
||||
}
|
||||
|
||||
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 {backupColumns} from "@/features/backup/columns";
|
||||
import {restoreColumns} from "@/features/restore/columns";
|
||||
import {Backup, Restauration} from "@prisma/client";
|
||||
import {Backup, Restoration} from "@prisma/client";
|
||||
|
||||
export type DatabaseTabsProps = {
|
||||
backups: Backup[]
|
||||
restaurations: Restauration[]
|
||||
restorations: Restoration[]
|
||||
isAlreadyRestore: boolean
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ export const DatabaseTabs = (props: DatabaseTabsProps) => {
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent className="h-full justify-between" value="restore">
|
||||
<DataTableWithPagination columns={restoreColumns} data={props.restaurations}/>
|
||||
<DataTableWithPagination columns={restoreColumns} data={props.restorations}/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
)
|
||||
|
||||
@@ -36,8 +36,6 @@ export const DatabaseForm = (props: DatabaseFormProps) => {
|
||||
defaultValues: {...defaultValues},
|
||||
});
|
||||
|
||||
console.log("aaaaaaaaaa", form.getValues())
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const mutation = useMutation({
|
||||
|
||||
@@ -15,7 +15,7 @@ import {ReloadIcon} from "@radix-ui/react-icons";
|
||||
import {Backup} from "@prisma/client";
|
||||
import {getFileUrlPresignedLocal} from "@/features/upload/private/upload.action";
|
||||
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 {useRouter} from "next/navigation";
|
||||
import {TooltipCustom} from "@/components/wrappers/TooltipCustom/TooltipCustom";
|
||||
@@ -50,7 +50,7 @@ export const backupColumns: ColumnDef<Backup>[] = [
|
||||
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()
|
||||
|
||||
@@ -62,15 +62,15 @@ export const backupColumns: ColumnDef<Backup>[] = [
|
||||
|
||||
const mutationRestore = useMutation({
|
||||
mutationFn: async () => {
|
||||
const restauration = await createRestaurationAction({
|
||||
const restoration = await createRestorationAction({
|
||||
backupId: rowData.id,
|
||||
databaseId: rowData.databaseId
|
||||
})
|
||||
if (restauration.data.success) {
|
||||
toast.success(restauration.data.actionSuccess?.message || "Restauration created successfully!");
|
||||
if (restoration.data.success) {
|
||||
toast.success(restoration.data.actionSuccess?.message || "Restoration created successfully!");
|
||||
router.refresh()
|
||||
} 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>
|
||||
{status == "success" ?
|
||||
<>
|
||||
<TooltipCustom disabled={extendedProps} text="Already a restauration waiting">
|
||||
<TooltipCustom disabled={extendedProps} text="Already a restoration waiting">
|
||||
<DropdownMenuItem disabled={mutationRestore.isPending || extendedProps}
|
||||
onClick={async () => {
|
||||
await handleRestore()
|
||||
|
||||
@@ -12,11 +12,11 @@ import {
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {Download, MoreHorizontal, Trash2} from "lucide-react";
|
||||
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",
|
||||
header: "Reference",
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
"use server"
|
||||
|
||||
import {userAction} from "@/safe-actions";
|
||||
import {z} from "zod";
|
||||
import {prisma} from "@/prisma";
|
||||
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({
|
||||
backupId: z.string(),
|
||||
databaseId: z.string(),
|
||||
}))
|
||||
.action(async ({parsedInput, ctx}): Promise<ServerActionResult<Restauration>> => {
|
||||
.action(async ({parsedInput, ctx}): Promise<ServerActionResult<Restoration>> => {
|
||||
|
||||
try {
|
||||
const restauration = await prisma.restauration.create({
|
||||
const restoration = await prisma.restoration.create({
|
||||
data: {
|
||||
databaseId: parsedInput.databaseId,
|
||||
backupId: parsedInput.backupId,
|
||||
@@ -24,14 +25,14 @@ export const createRestaurationAction = userAction
|
||||
|
||||
return {
|
||||
success: true,
|
||||
value: restauration,
|
||||
value: restoration,
|
||||
actionSuccess: {
|
||||
message: "Restoration has been successfully created.",
|
||||
messageParams: { restaurationId: restauration.id },
|
||||
messageParams: { restorationId: restoration.id },
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error creating restauration:", error);
|
||||
console.error("Error creating restoration:", error);
|
||||
return {
|
||||
success: false,
|
||||
actionError: {
|
||||
|
||||
@@ -53,7 +53,7 @@ export const databases = [
|
||||
"lastContact": "2024-11-28T08:30:00.000Z",
|
||||
"projectId": "proj-789",
|
||||
"backups": [],
|
||||
"restaurations": []
|
||||
"restorations": []
|
||||
},
|
||||
{
|
||||
"id": "1e4f9265-5f10-4bd4-8e5c-3283746cfd7a",
|
||||
@@ -67,7 +67,7 @@ export const databases = [
|
||||
"lastContact": "2024-11-25T10:15:00.000Z",
|
||||
"projectId": null,
|
||||
"backups": [],
|
||||
"restaurations": []
|
||||
"restorations": []
|
||||
},
|
||||
{
|
||||
"id": "b6f92bd7-834b-41c1-b6b3-dc4214b1de08",
|
||||
@@ -81,7 +81,7 @@ export const databases = [
|
||||
"lastContact": null,
|
||||
"projectId": "proj-456",
|
||||
"backups": [],
|
||||
"restaurations": []
|
||||
"restorations": []
|
||||
}
|
||||
]
|
||||
|
||||
@@ -108,7 +108,7 @@ export const backups = [
|
||||
{'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-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'},
|
||||
|
||||
Reference in New Issue
Block a user