The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore: adjust database health report with org billing
Kevin Grünebergc9e20d180039
diff --git a/studio/components/interfaces/BillingV2/NoProjectsOnPaidOrgInfo.tsx b/studio/components/interfaces/BillingV2/NoProjectsOnPaidOrgInfo.tsxindex fde24bc8efb..973998ca6c6 100644--- a/studio/components/interfaces/BillingV2/NoProjectsOnPaidOrgInfo.tsx+++ b/studio/components/interfaces/BillingV2/NoProjectsOnPaidOrgInfo.tsx@@ -12,14 +12,14 @@ interface Props {const NoProjectsOnPaidOrgInfo: FC<Props> = ({ organization }) => {const { data: allProjects } = useProjectsQuery({- enabled: organization?.subscription_id !== undefined,+ enabled: organization?.subscription_id != undefined,})const projectCount =allProjects?.filter((project) => project.organization_id === organization?.id).length ?? 0const { data: orgSubscription } = useOrgSubscriptionQuery({ orgSlug: organization?.slug },- { enabled: organization?.subscription_id !== undefined }+ { enabled: organization?.subscription_id != undefined })if (projectCount > 0 || orgSubscription?.plan === undefined || orgSubscription.plan.id === 'free')diff --git a/studio/pages/new/[slug].tsx b/studio/pages/new/[slug].tsxindex cda74baff83..ac424100810 100644--- a/studio/pages/new/[slug].tsx+++ b/studio/pages/new/[slug].tsx@@ -89,7 +89,7 @@ const Wizard: NextPageWithLayout = () => {)const { data: allProjects } = useProjectsQuery({- enabled: currentOrg?.subscription_id !== undefined,+ enabled: currentOrg?.subscription_id != undefined,})const orgProjectCount = (allProjects || []).filter(diff --git a/studio/pages/project/[ref]/reports/database.tsx b/studio/pages/project/[ref]/reports/database.tsxindex 49367c6f4e5..fcec21f4fc3 100644--- a/studio/pages/project/[ref]/reports/database.tsx+++ b/studio/pages/project/[ref]/reports/database.tsx@@ -17,6 +17,8 @@ import SparkBar from 'components/ui/SparkBar'import { useDatabaseSizeQuery } from 'data/database/database-size-query'import { useProjectSubscriptionV2Query } from 'data/subscriptions/project-subscription-v2-query'import { useProjectUsageQuery } from 'data/usage/project-usage-query'+import { useSelectedOrganization } from 'hooks'+import Link from 'next/link'const DatabaseReport: NextPageWithLayout = () => {return (@@ -37,12 +39,13 @@ export default DatabaseReportconst DatabaseUsage = observer(() => {const { ref: projectRef } = useParams()const { project } = useProjectContext()+ const selectedOrganization = useSelectedOrganization()const { data: usage } = useProjectUsageQuery({ projectRef })const { data: subscription } = useProjectSubscriptionV2Query({ projectRef })const [dateRange, setDateRange] = useState<any>(undefined)- const databaseSizeLimit = usage?.db_size?.limit ?? 0+ const databaseUsageLimit = usage?.db_size?.limit ?? 0const databaseEgressLimit = usage?.db_egress?.limit ?? 0const { data } = useDatabaseSizeQuery({@@ -51,9 +54,12 @@ const DatabaseUsage = observer(() => {})const databaseSize = data?.result[0].db_size ?? 0- const databaseSizeUsageRatio = databaseSize / databaseSizeLimit- const sizeIsApproaching = databaseSizeUsageRatio >= USAGE_APPROACHING_THRESHOLD- const sizeIsExceeded = databaseSizeUsageRatio >= 1+ const databaseSizeUsageRatio = databaseSize / databaseUsageLimit+ const limitIsApproaching = databaseSizeUsageRatio >= USAGE_APPROACHING_THRESHOLD+ const limitIsExceeded = databaseSizeUsageRatio >= 1++ const diskSize = usage?.disk_volume_size_gb ?? 0+ const diskSizeUsageRatio = databaseSize / diskSizeconst egressIsApproaching = databaseSizeUsageRatio >= USAGE_APPROACHING_THRESHOLDconst egressIsExceeded = databaseSizeUsageRatio >= 1@@ -62,66 +68,139 @@ const DatabaseUsage = observer(() => {const isPaidTier = subscriptionPlan !== 'free'+ // Can be null or undefined, thus !=+ const orgLevelBilling = selectedOrganization?.subscription_id != undefined+return (<><div><section><Panel title={<h2>Database usage</h2>}>- <Panel.Content>- <div className="space-y-1">- <h5 className="text-sm text-scale-1200">Database size</h5>- <SparkBar- type="horizontal"- value={databaseSize}- max={databaseSizeLimit > 0 ? databaseSizeLimit : Infinity}- barClass={`${- sizeIsExceeded ? 'bg-red-900' : sizeIsApproaching ? 'bg-yellow-900' : 'bg-brand'- }`}- labelBottom={formatBytes(databaseSize)}- labelTop={databaseSizeLimit > 0 ? formatBytes(databaseSizeLimit) : ''}- />- </div>+ {orgLevelBilling ? (+ <Panel.Content>+ <div className="space-y-1">+ <h5 className="text-sm text-scale-1200">Disk Usage</h5>+ <SparkBar+ type="horizontal"+ value={databaseSize}+ max={+ usage?.disk_volume_size_gb ?? 0 > 0+ ? usage?.disk_volume_size_gb ?? 0+ : Infinity+ }+ barClass={`${+ diskSizeUsageRatio >= 0.9 && !isPaidTier+ ? 'bg-red-900'+ : diskSizeUsageRatio >= 0.9+ ? 'bg-yellow-900'+ : 'bg-brand'+ }`}+ bgClass="bg-gray-300 dark:bg-gray-600"+ labelBottom={formatBytes(databaseSize)}+ labelTop={usage?.disk_volume_size_gb ? usage?.disk_volume_size_gb + 'GB' : '-'}+ />+ </div>++ {isPaidTier && (+ <div className="flex justify-between items-center mt-3">+ <div className="flex flex-row space-x-3 text-scale-1000 text-sm">+ <Badge>Auto-Scaling</Badge>+ </div>- {isPaidTier && (- <div className="flex justify-between items-center mt-3">- <div className="flex flex-row space-x-3 text-scale-1000 text-sm">- {usage?.disk_volume_size_gb && (- <span>Disk Size: {usage.disk_volume_size_gb} GB</span>- )}- <Badge>Auto-Scaling</Badge>+ <Button type="default" icon={<IconExternalLink size={14} strokeWidth={1.5} />}>+ <a+ target="_blank"+ rel="noreferrer"+ href="https://supabase.com/docs/guides/platform/database-usage"+ >+ What is disk size?+ </a>+ </Button></div>+ )}+ </Panel.Content>+ ) : (+ <Panel.Content>+ <div className="space-y-1">+ <h5 className="text-sm text-scale-1200">Database size</h5>+ <SparkBar+ type="horizontal"+ value={databaseSize}+ max={databaseUsageLimit > 0 ? databaseUsageLimit : Infinity}+ barClass={`${+ limitIsExceeded+ ? 'bg-red-900'+ : limitIsApproaching+ ? 'bg-yellow-900'+ : 'bg-brand'+ }`}+ bgClass="bg-gray-300 dark:bg-gray-600"+ labelBottom={formatBytes(databaseSize)}+ labelTop={databaseUsageLimit > 0 ? formatBytes(databaseUsageLimit) : ''}+ />+ </div>- <Button type="default" icon={<IconExternalLink size={14} strokeWidth={1.5} />}>- <a- target="_blank"- rel="noreferrer"- href="https://supabase.com/docs/guides/platform/database-usage"- >- What is disk size?- </a>- </Button>+ {isPaidTier && (+ <div className="flex justify-between items-center mt-3">+ <div className="flex flex-row space-x-3 text-scale-1000 text-sm">+ {usage?.disk_volume_size_gb && (+ <span>Disk Size: {usage.disk_volume_size_gb} GB</span>+ )}+ <Badge>Auto-Scaling</Badge>+ </div>++ <Button type="default" icon={<IconExternalLink size={14} strokeWidth={1.5} />}>+ <a+ target="_blank"+ rel="noreferrer"+ href="https://supabase.com/docs/guides/platform/database-usage"+ >+ What is disk size?+ </a>+ </Button>+ </div>+ )}+ </Panel.Content>+ )}++ {!orgLevelBilling && (+ <Panel.Content>+ <div className="space-y-1">+ <h5 className="text-sm text-scale-1200">Database egress</h5>+ <SparkBar+ type="horizontal"+ value={usage?.db_egress?.usage ?? 0}+ max={databaseEgressLimit > 0 ? databaseEgressLimit : Infinity}+ barClass={`${+ egressIsExceeded+ ? 'bg-red-900'+ : egressIsApproaching+ ? 'bg-yellow-900'+ : 'bg-brand'+ }`}+ bgClass="bg-gray-300 dark:bg-gray-600"+ labelBottom={formatBytes(usage?.db_egress?.usage ?? 0)}+ labelTop={databaseEgressLimit > 0 ? formatBytes(databaseEgressLimit) : ''}+ /></div>- )}- </Panel.Content>- <Panel.Content>- <div className="space-y-1">- <h5 className="text-sm text-scale-1200">Database egress</h5>- <SparkBar- type="horizontal"- value={usage?.db_egress?.usage ?? 0}- max={databaseEgressLimit > 0 ? databaseEgressLimit : Infinity}- barClass={`${- egressIsExceeded- ? 'bg-red-900'- : egressIsApproaching- ? 'bg-yellow-900'- : 'bg-brand'- }`}- labelBottom={formatBytes(usage?.db_egress?.usage ?? 0)}- labelTop={databaseEgressLimit > 0 ? formatBytes(databaseEgressLimit) : ''}- />- </div>- </Panel.Content>+ </Panel.Content>+ )}++ {orgLevelBilling && (+ <Panel.Content>+ <p className="text-sm text-scale-1200">+ Head to your{' '}+ <Link href={`/org/${selectedOrganization?.slug}/usage`}>+ <a>+ <span className="text-green-900 transition hover:text-green-1000">+ organizations usage page+ </span>+ </a>+ </Link>+ , to see a breakdown of your entire usage.+ </p>+ </Panel.Content>+ )}</Panel><Panel title={<h2>Database health</h2>}>diff --git a/studio/types/base.ts b/studio/types/base.tsindex 8c99c88ed41..e19dccda4e8 100644--- a/studio/types/base.ts+++ b/studio/types/base.ts@@ -9,7 +9,7 @@ export interface Organization {is_owner?: booleanstripe_customer_id?: stringopt_in_tags: string[]- subscription_id?: string+ subscription_id?: string | null}export interface ProjectBase {