mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
fix: database health cron
This commit is contained in:
@@ -7,6 +7,7 @@ import * as drizzleDb from "@/db";
|
||||
import {BackupWith, Restoration} from "@/db/schema/07_database";
|
||||
import {getOrganizationChannels} from "@/db/services/notification-channel";
|
||||
import {getOrganizationStorageChannels} from "@/db/services/storage-channel";
|
||||
import {getHealthLast12hLogs} from "@/db/services/healthcheck";
|
||||
|
||||
export const getDatabaseDataAction = userAction
|
||||
.schema(
|
||||
@@ -50,7 +51,9 @@ export const getDatabaseDataAction = userAction
|
||||
const successfulBackups = backups.filter(b => b.status === "success").length;
|
||||
const successRate = totalBackups > 0 ? (successfulBackups / totalBackups) * 100 : null;
|
||||
|
||||
// @ts-ignore
|
||||
let activeOrganizationChannels = [];
|
||||
// @ts-ignore
|
||||
let activeOrganizationStorageChannels = [];
|
||||
|
||||
if (database?.project?.organizationId) {
|
||||
@@ -61,16 +64,20 @@ export const getDatabaseDataAction = userAction
|
||||
activeOrganizationStorageChannels = organizationStorageChannels.filter(channel => channel.enabled);
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
database,
|
||||
backups,
|
||||
restorations,
|
||||
// @ts-ignore
|
||||
activeOrganizationChannels,
|
||||
// @ts-ignore
|
||||
activeOrganizationStorageChannels,
|
||||
stats: {
|
||||
totalBackups,
|
||||
availableBackups,
|
||||
successRate
|
||||
}
|
||||
},
|
||||
health: database ? await getHealthLast12hLogs({ id: database.id }) : []
|
||||
};
|
||||
});
|
||||
@@ -3,7 +3,7 @@ import {z} from "zod";
|
||||
export const PolicySchema = z.object({
|
||||
channelId: z.string().min(1, "Please select channel"),
|
||||
eventKinds: z.array(z.enum([
|
||||
'error_backup', 'error_restore', 'success_restore', 'success_backup', 'weekly_report'
|
||||
'error_backup', 'error_restore', 'success_restore', 'success_backup', 'weekly_report', 'error_health_database'
|
||||
]))
|
||||
.optional(),
|
||||
enabled: z.boolean().default(true),
|
||||
@@ -17,16 +17,16 @@ export const PoliciesSchema = z.object({
|
||||
export type PoliciesType = z.infer<typeof PoliciesSchema>;
|
||||
export type PolicyType = z.infer<typeof PolicySchema>;
|
||||
|
||||
|
||||
export const EVENT_KIND_OPTIONS = [
|
||||
{label: "Error Backup", value: "error_backup"},
|
||||
{label: "Error Restore", value: "error_restore"},
|
||||
{label: "Success Restore", value: "success_restore"},
|
||||
{label: "Success Backup", value: "success_backup"},
|
||||
// {label: "Weekly Report", value: "weekly_report"},
|
||||
];
|
||||
|
||||
export const EVENT_KIND_BACKUP_ONLY_OPTIONS = [
|
||||
{label: "Error Backup", value: "error_backup"},
|
||||
{label: "Success Backup", value: "success_backup"},
|
||||
];
|
||||
{label: "Health Ping Fail", value: "error_health_database"},
|
||||
];
|
||||
|
||||
export const EVENT_KIND_OPTIONS = [
|
||||
...EVENT_KIND_BACKUP_ONLY_OPTIONS,
|
||||
{label: "Error Restore", value: "error_restore"},
|
||||
{label: "Success Restore", value: "success_restore"},
|
||||
// {label: "Weekly Report", value: "weekly_report"},
|
||||
];
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
"use client"
|
||||
|
||||
import {useState} from "react";
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {DatabaseWith} from "@/db/schema/07_database";
|
||||
import {HeartPulse} from "lucide-react";
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetTitle,
|
||||
SheetTrigger
|
||||
} from "@/components/ui/sheet";
|
||||
import {HealthcheckLog} from "@/db/schema/15_healthcheck-log";
|
||||
import {HealthCheckGraph} from "@/components/wrappers/dashboard/health/heath-grid";
|
||||
|
||||
type HealthModalProps = {
|
||||
database: DatabaseWith,
|
||||
healthLogs: HealthcheckLog[]
|
||||
}
|
||||
|
||||
export const HealthModal = ({database, healthLogs}: HealthModalProps) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<Sheet open={open} onOpenChange={setOpen}>
|
||||
<SheetTrigger asChild>
|
||||
<Button variant="outline" onClick={() => setOpen(true)}>
|
||||
<HeartPulse/>
|
||||
</Button>
|
||||
</SheetTrigger>
|
||||
<SheetContent side="bottom">
|
||||
<div className="flex pl-5 pt-4">
|
||||
<SheetTitle>
|
||||
Database Health Status
|
||||
</SheetTitle>
|
||||
</div>
|
||||
<div className="px-4 pb-5">
|
||||
<HealthCheckGraph logs={healthLogs} />
|
||||
</div>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
)
|
||||
}
|
||||
@@ -20,6 +20,8 @@ import { ChannelPoliciesModal } from "@/components/wrappers/dashboard/database/c
|
||||
import { HardDrive, Megaphone } from "lucide-react";
|
||||
import { ImportModal } from "@/components/wrappers/dashboard/database/import/import-modal";
|
||||
import { BackupButton } from "@/components/wrappers/dashboard/backup/backup-button/backup-button";
|
||||
import {HealthModal} from "@/components/wrappers/dashboard/database/health/health-modal";
|
||||
import {HealthcheckLog} from "@/db/schema/15_healthcheck-log";
|
||||
|
||||
export type DatabaseContentProps = {
|
||||
settings: Setting;
|
||||
@@ -34,6 +36,7 @@ export type DatabaseContentProps = {
|
||||
organizationId: string;
|
||||
activeOrganizationChannels: any[];
|
||||
activeOrganizationStorageChannels: any[];
|
||||
databaseHealthLogs: HealthcheckLog[]
|
||||
};
|
||||
|
||||
export const DatabaseContent = (props: DatabaseContentProps) => {
|
||||
@@ -64,6 +67,7 @@ export const DatabaseContent = (props: DatabaseContentProps) => {
|
||||
availableBackups: props.availableBackups,
|
||||
successRate: props.successRate,
|
||||
},
|
||||
health: props.databaseHealthLogs
|
||||
},
|
||||
staleTime: 0,
|
||||
gcTime: 0,
|
||||
@@ -118,10 +122,13 @@ export const DatabaseContent = (props: DatabaseContentProps) => {
|
||||
organizationId={props.organizationId}
|
||||
/>
|
||||
<ImportModal database={database} />
|
||||
<HealthModal database={database} healthLogs={data?.health ?? []}/>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<BackupButton
|
||||
disable={isAlreadyBackup}
|
||||
disable={isAlreadyBackup || !database.lastContact}
|
||||
databaseId={database.id}
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user