import { useNavigate } from '@tanstack/react-router' import { useParams } from 'common' import { cn } from 'ui' import { CodeBlock } from 'ui-patterns/CodeBlock' import { InfoTooltip } from 'ui-patterns/info-tooltip' import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader' import { buildDirectPostgresConnectionUri, buildLogicalBackupShellScript, DB_PASSWORD_PLACEHOLDER, } from './LogicalBackupCliInstructions.utils' import { ButtonTooltip } from '@/components/ui/ButtonTooltip' import { InlineLink } from '@/components/ui/InlineLink' import { useProjectSettingsV2Query } from '@/data/config/project-settings-v2-query' import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2' import { DOCS_URL } from '@/lib/constants' export type LogicalBackupCliInstructionsProps = { enabled?: boolean className?: string showResetPassword?: boolean note?: string } export const LogicalBackupCliInstructions = ({ enabled = true, className, showResetPassword = true, note, }: LogicalBackupCliInstructionsProps) => { const navigate = useNavigate() const { ref } = useParams() const { can: canResetDbPassword } = useAsyncCheckPermissionsV2( FGA_PERMISSIONS.PROJECT.DATABASE_CONFIG_WRITE ) const { data: settings, isSuccess, isError, } = useProjectSettingsV2Query({ projectRef: ref }, { enabled: enabled && Boolean(ref) }) const connectionUri = isSuccess && settings ? buildDirectPostgresConnectionUri({ db_user: settings.db_user, db_host: settings.db_host, db_port: settings.db_port, db_name: settings.db_name, }) : null const shellScript = connectionUri ? buildLogicalBackupShellScript(connectionUri) : '' const resetPasswordHref = ref ? `/project/${ref}/database/settings#database-password` : '#' const resetDisabled = !canResetDbPassword return (
Use your direct connection string to backup your database, replacing{' '}
Examples:{DB_PASSWORD_PLACEHOLDER} with your database
password. Percent-encode any reserved character in your password before using it in the
URL
%
→
%25
@
→
%40
:
→
%3A
/
→
%2F
#
→
%23
See the{' '}
{note}
} {isError && (
Could not load connection details. Open{' '}