import Link from 'next/link' import { useMemo } from 'react' import { Alert, AlertDescription, AlertTitle, Button, CriticalIcon } from 'ui' import { InfoTooltip } from 'ui-patterns/info-tooltip' import { SectionContent } from '../SectionContent' import { CategoryAttribute } from '../Usage.constants' import Panel from '@/components/ui/Panel' import { PricingMetric } from '@/data/analytics/org-daily-stats-query' import type { OrgSubscription } from '@/data/subscriptions/types' import { OrgUsageResponse } from '@/data/usage/org-usage-query' import { formatBytes } from '@/lib/helpers' export interface DatabaseSizeUsageProps { slug: string projectRef?: string | null attribute: CategoryAttribute subscription?: OrgSubscription usage?: OrgUsageResponse currentBillingCycleSelected: boolean } const DatabaseSizeUsage = ({ attribute, subscription, usage, currentBillingCycleSelected, }: DatabaseSizeUsageProps) => { const databaseSizeUsage = useMemo( () => usage?.usages.find((it) => it.metric === PricingMetric.DATABASE_SIZE), [usage] ) const hasProjectsExceedingDatabaseSize = useMemo(() => { return databaseSizeUsage?.project_allocations.some((it) => it.usage > 0.5 * 1e9) }, [databaseSizeUsage]) return (
{currentBillingCycleSelected && hasProjectsExceedingDatabaseSize && ( Projects exceeding quota You have projects that are exceeding 0.5 GB of database size. Reduce the database size or upgrade to a paid plan. )}

{attribute.name} usage

{subscription?.plan.id !== 'platform' && ( <>

Included in {subscription?.plan?.name} Plan

0.5 GB per project

Max database size

{databaseSizeUsage?.usage ? formatBytes(databaseSizeUsage?.usage_original) : '-'}

)}
{currentBillingCycleSelected && subscription?.plan.id !== 'platform' ? (

Current database size per project

{databaseSizeUsage?.project_allocations.length === 0 && (

No active projects

You don't have any active projects in this organization.

)} {databaseSizeUsage?.project_allocations.map((project, idx) => { return (
{project.name}
{formatBytes(project.usage)} {' '} Database Size

{formatBytes(project.usage)} GB database size as reported by Postgres.

) })}
) : (

Data not available

Switch to current billing cycle to see current database size per project.

)}
) } export default DatabaseSizeUsage