Documentation
¶
Index ¶
- Constants
- Variables
- func Aqua(str string) string
- func AssertProjectRefIsValid(projectRef string) error
- func AssertServiceIsRunning(ctx context.Context, containerId string) error
- func AssertSupabaseDbIsRunning() error
- func AwsRegions() []string
- func BindHostModules(cwd, relEntrypointPath, relImportMapPath string, fsys afero.Fs) ([]string, error)
- func Bold(str string) string
- func ChangeWorkDir(fsys afero.Fs) error
- func CliProjectFilter(projectId string) filters.Args
- func ConnectByConfig(ctx context.Context, config pgconn.Config, options ...func(*pgx.ConnConfig)) (*pgx.Conn, error)
- func ConnectByConfigStream(ctx context.Context, config pgconn.Config, w io.Writer, ...) (*pgx.Conn, error)
- func ConnectByUrl(ctx context.Context, url string, options ...func(*pgx.ConnConfig)) (*pgx.Conn, error)
- func ConnectLocalPostgres(ctx context.Context, config pgconn.Config, options ...func(*pgx.ConnConfig)) (*pgx.Conn, error)
- func DeleteAccessToken(fsys afero.Fs) error
- func DockerExecOnce(ctx context.Context, containerId string, env []string, cmd []string) (string, error)
- func DockerExecOnceWithStream(ctx context.Context, containerId, workdir string, env, cmd []string, ...) error
- func DockerImagePull(ctx context.Context, imageTag string, w io.Writer) error
- func DockerImagePullWithRetry(ctx context.Context, image string, retries int) error
- func DockerNetworkCreateIfNotExists(ctx context.Context, mode container.NetworkMode, labels map[string]string) error
- func DockerPullImageIfNotCached(ctx context.Context, imageName string) error
- func DockerRemove(containerId string)
- func DockerRemoveAll(ctx context.Context, w io.Writer, projectId string) error
- func DockerRunJob(ctx context.Context, job DockerJob, stdout, stderr io.Writer) error
- func DockerRunOnce(ctx context.Context, image string, env []string, cmd []string) (string, error)
- func DockerRunOnceWithConfig(ctx context.Context, config container.Config, hostConfig container.HostConfig, ...) error
- func DockerRunOnceWithStream(ctx context.Context, image string, env, cmd []string, stdout, stderr io.Writer) error
- func DockerStart(ctx context.Context, config container.Config, hostConfig container.HostConfig, ...) (string, error)
- func DockerStreamLogs(ctx context.Context, containerId string, stdout, stderr io.Writer, ...) error
- func DockerStreamLogsOnce(ctx context.Context, containerId string, stdout, stderr io.Writer) error
- func EncodeOutput(format string, w io.Writer, value any) error
- func FallbackLookupIP(ctx context.Context, host string) ([]string, error)
- func FormatRegion(region string) string
- func FormatTime(t time.Time) string
- func FormatTimestamp(timestamp string) string
- func FormatTimestampVersion(timestamp string) string
- func GetApiUrl(path string) string
- func GetCurrentBranchFS(fsys afero.Fs) (string, error)
- func GetCurrentTimestamp() string
- func GetDebugLogger() io.Writer
- func GetDeclarativeDir() string
- func GetDenoPath() (string, error)
- func GetDockerIds() []string
- func GetGitBranch(fsys afero.Fs) string
- func GetGitBranchOrDefault(def string, fsys afero.Fs) string
- func GetGitHubClient(ctx context.Context) *github.Client
- func GetHostname() string
- func GetId(name string) string
- func GetLatestRelease(ctx context.Context) (string, error)
- func GetOrgBillingURL(orgSlug string) string
- func GetOrgSlugFromProjectRef(ctx context.Context, projectRef string) (string, error)
- func GetPoolerConfig(projectRef string) *pgconn.Config
- func GetPoolerConfigPrimary(ctx context.Context, ref string) (api.SupavisorConfigResponse, error)
- func GetRegistry() string
- func GetRegistryAuth() string
- func GetRegistryImageUrl(imageName string) string
- func GetServices() types.Services
- func GetSupabase() *supabase.ClientWithResponses
- func GetSupabaseAPIHost() string
- func GetSupabaseDashboardURL() string
- func GetSupabaseDbHost(projectRef string) string
- func GetSupabaseHost(projectRef string) string
- func Green(str string) string
- func InitConfig(params InitParams, fsys afero.Fs) error
- func InstallOrUpgradeDeno(ctx context.Context, fsys afero.Fs) error
- func IsAgentMode() bool
- func IsBranchNameReserved(branch string) bool
- func IsDockerRunning(ctx context.Context) bool
- func IsGitIgnored(fp ...string) (bool, error)
- func IsGitRepo() bool
- func IsLocalDatabase(config pgconn.Config) bool
- func IsPgDeltaEnabled() bool
- func LoadAccessTokenFS(fsys afero.Fs) (string, error)
- func LoadProfile(ctx context.Context, fsys afero.Fs) error
- func MkdirIfNotExist(path string) error
- func MkdirIfNotExistFS(fsys afero.Fs, path string) error
- func NewBackoffPolicy(ctx context.Context) backoff.BackOffContext
- func NewDocker() *client.Client
- func NewErrorCallback(callbacks ...func(attempt uint) error) backoff.Notify
- func NewRootFS(fsys afero.Fs) fs.FS
- func ParsePoolerURL(connString string) (*pgconn.Config, error)
- func ProcessDiffOutput(diffBytes []byte) ([]byte, error)
- func ProcessDiffProgress(p Program, out io.Reader) error
- func ProcessPullOutput(out io.ReadCloser, p Program) error
- func Red(str string) string
- func RemoveDuplicates[T comparable](slice []T) (result []T)
- func RenderTable(markdown string) error
- func ResolveCNAME(ctx context.Context, host string) (string, error)
- func RunEdgeRuntimeScript(ctx context.Context, env []string, script string, binds []string, ...) error
- func RunProgram(ctx context.Context, f func(p Program, ctx context.Context) error) error
- func SaveAccessToken(accessToken string, fsys afero.Fs) error
- func SaveProfileName(prof string, fsys afero.Fs) error
- func SetConnectSuggestion(err error)
- func ShortContainerImageName(imageName string) string
- func SuggestClaudePlugin() string
- func SuggestUpgradeOnError(ctx context.Context, projectRef, featureKey string, statusCode int) (orgSlug string, isGated bool)
- func ToDockerPath(absHostPath string) string
- func ToEnvMap(value any) (map[string]string, error)
- func ToPostgresURL(config pgconn.Config) string
- func ToRealtimeEnv(addr config.AddressFamily) string
- func UpdateDockerIds()
- func ValidateFunctionSlug(slug string) error
- func WaitAll[T any](containers []T, exec func(container T) error) []error
- func WriteConfig(fsys afero.Fs, _test bool) error
- func WriteFile(path string, contents []byte, fsys afero.Fs) error
- func Yellow(str string) string
- type Console
- type DenoScriptDir
- type DialContextFunc
- type DiffDependencies
- type DiffEntry
- type DiffStream
- type DockerJob
- type EnumFlag
- type InitParams
- type Profile
- type Program
- type ProgressMsg
- type PromptItem
- type PsqlMsg
- type StatusMsg
- type StatusWriter
Constants ¶
const ( DNS_GO_NATIVE = "native" DNS_OVER_HTTPS = "https" )
const ( SUPERUSER_ROLE = "supabase_admin" CLI_LOGIN_PREFIX = "cli_login_" SET_SESSION_ROLE = "SET SESSION ROLE postgres" )
const ( // Legacy bundle options DockerDenoDir = "/home/deno" DockerEszipDir = "/root/eszips" DenoVersion = "1.30.3" )
const ( DinDHost = "host.docker.internal" CliProjectLabel = "com.supabase.cli.project" )
const ( OutputEnv = "env" OutputJson = "json" OutputPretty = "pretty" OutputToml = "toml" OutputYaml = "yaml" // OutputMetadata is used with certain SSO commands only. OutputMetadata = "metadata" )
const ( CLI_OWNER = "supabase" CLI_REPO = "cli" )
const AccessTokenKey = "access-token"
const HeaderGotrueID = "X-Gotrue-Id"
const SuggestDebugFlag = "Try rerunning the command with --debug to troubleshoot the error."
const SuggestEnvVar = "Connect to your database by setting the env var correctly: SUPABASE_DB_PASSWORD"
Variables ¶
var ( AccessTokenPattern = regexp.MustCompile(`^sbp_(oauth_)?[a-f0-9]{40}$`) ErrInvalidToken = errors.New("Invalid access token format. Must be like `sbp_0102...1920`.") ErrMissingToken = errors.Errorf("Access token not provided. Supply an access token by running %s or setting the SUPABASE_ACCESS_TOKEN environment variable.", Aqua("supabase login")) ErrNotLoggedIn = errors.New("You were not logged in, nothing to do.") )
var ( NetId string DbId string KongId string GotrueId string InbucketId string RealtimeId string RestId string StorageId string ImgProxyId string DifferId string PgmetaId string StudioId string EdgeRuntimeId string LogflareId string VectorId string PoolerId string DbAliases = []string{"db", "db.supabase.internal"} KongAliases = []string{"kong", "api.supabase.internal"} GotrueAliases = []string{"auth"} InbucketAliases = []string{"inbucket"} RealtimeAliases = []string{"realtime", Config.Realtime.TenantId} RestAliases = []string{"rest"} StorageAliases = []string{"storage"} ImgProxyAliases = []string{"imgproxy"} PgmetaAliases = []string{"pg_meta"} StudioAliases = []string{"studio"} EdgeRuntimeAliases = []string{"edge_runtime"} LogflareAliases = []string{"analytics"} VectorAliases = []string{"vector"} PoolerAliases = []string{"pooler"} //go:embed templates/initial_schemas/13.sql InitialSchemaPg13Sql string //go:embed templates/initial_schemas/14.sql InitialSchemaPg14Sql string )
var ( Version string SentryDsn string PostHogAPIKey string PostHogEndpoint string )
Assigned using `-ldflags` https://stackoverflow.com/q/11354518
var ( CmdSuggestion string CurrentDirAbs string // pg_dumpall --globals-only --no-role-passwords --dbname $DB_URL \ // | sed '/^CREATE ROLE postgres;/d' \ // | sed '/^ALTER ROLE postgres WITH /d' \ // | sed "/^ALTER ROLE .* WITH .* LOGIN /s/;$/ PASSWORD 'postgres';/" //go:embed templates/globals.sql GlobalsSql string ProjectRefPattern = regexp.MustCompile(`^[a-z]{20}$`) UUIDPattern = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`) ProjectHostPattern = regexp.MustCompile(`^(db\.)([a-z]{20})\.supabase\.(co|red)$`) BranchNamePattern = regexp.MustCompile(`[[:word:]-]+`) FuncSlugPattern = regexp.MustCompile(`^[A-Za-z][A-Za-z0-9_-]*$`) ImageNamePattern = regexp.MustCompile(`\/(.*):`) // These schemas are ignored from db diff and db dump PgSchemas = migration.InternalSchemas[:2] InternalSchemas = migration.InternalSchemas SupabaseDirPath = "supabase" ConfigPath = filepath.Join(SupabaseDirPath, "config.toml") GitIgnorePath = filepath.Join(SupabaseDirPath, ".gitignore") TempDir = filepath.Join(SupabaseDirPath, ".temp") ImportMapsDir = filepath.Join(TempDir, "import_maps") ProjectRefPath = filepath.Join(TempDir, "project-ref") PoolerUrlPath = filepath.Join(TempDir, "pooler-url") PostgresVersionPath = filepath.Join(TempDir, "postgres-version") GotrueVersionPath = filepath.Join(TempDir, "gotrue-version") RestVersionPath = filepath.Join(TempDir, "rest-version") StorageVersionPath = filepath.Join(TempDir, "storage-version") StorageMigrationPath = filepath.Join(TempDir, "storage-migration") StudioVersionPath = filepath.Join(TempDir, "studio-version") PgmetaVersionPath = filepath.Join(TempDir, "pgmeta-version") PoolerVersionPath = filepath.Join(TempDir, "pooler-version") RealtimeVersionPath = filepath.Join(TempDir, "realtime-version") PgDeltaVersionPath = filepath.Join(TempDir, "pgdelta-version") CliVersionPath = filepath.Join(TempDir, "cli-latest") CurrBranchPath = filepath.Join(SupabaseDirPath, ".branches", "_current_branch") // DeclarativeDir is the canonical location for pg-delta declarative schema // files generated or synced by `supabase db schema declarative` commands. DeclarativeDir = filepath.Join(SupabaseDirPath, "database") ClusterDir = filepath.Join(SupabaseDirPath, "cluster") SchemasDir = filepath.Join(SupabaseDirPath, "schemas") MigrationsDir = filepath.Join(SupabaseDirPath, "migrations") FunctionsDir = filepath.Join(SupabaseDirPath, "functions") SnippetsDir = filepath.Join(SupabaseDirPath, "snippets") FallbackImportMapPath = filepath.Join(FunctionsDir, "import_map.json") FallbackEnvFilePath = filepath.Join(FunctionsDir, ".env") DbTestsDir = filepath.Join(SupabaseDirPath, "tests") CustomRolesPath = filepath.Join(SupabaseDirPath, "roles.sql") ErrNotLinked = errors.Errorf("Cannot find project ref. Have you run %s?", Aqua("supabase link")) ErrInvalidRef = errors.New("Invalid project ref format. Must be like `abcdefghijklmnopqrst`.") ErrInvalidSlug = errors.New("Invalid Function name. Must start with at least one letter, and only include alphanumeric characters, underscores, and hyphens. (^[A-Za-z][A-Za-z0-9_-]*$)") ErrNotRunning = errors.Errorf("%s is not running.", Aqua("supabase start")) )
var AgentMode = EnumFlag{ Allowed: []string{"auto", "yes", "no"}, Value: "auto", }
AgentMode is a global flag for overriding agent detection. Allowed values: "auto" (default), "yes", "no".
var Config = config.NewConfig(config.WithHostname(GetHostname()))
var ( DNSResolver = EnumFlag{ Allowed: []string{DNS_GO_NATIVE, DNS_OVER_HTTPS}, Value: DNS_GO_NATIVE, } )
var DefaultApiHost = CurrentProfile.APIURL
Used by unit tests
var ( // Used by unit tests DenoPathOverride string )
var Docker = NewDocker()
var ErrContainerKilled = errors.New("exit 137")
var ErrEnvNotSupported = errors.New("--output env flag is not supported")
var ErrPrimaryNotFound = errors.New("primary database not found")
var NoBackupVolume = false
NoBackupVolume TODO: encapsulate this state in a class
var OnGotrueID func(string)
var OutputFormat = EnumFlag{ Allowed: []string{ OutputEnv, OutputPretty, OutputJson, OutputToml, OutputYaml, }, Value: OutputPretty, }
Functions ¶
func AssertProjectRefIsValid ¶
func AssertServiceIsRunning ¶
func AssertSupabaseDbIsRunning ¶
func AssertSupabaseDbIsRunning() error
func AwsRegions ¶
func AwsRegions() []string
func BindHostModules ¶
func ChangeWorkDir ¶
func CliProjectFilter ¶
func ConnectByConfig ¶
func ConnectByConfigStream ¶
func ConnectByUrl ¶
func ConnectLocalPostgres ¶
func ConnectLocalPostgres(ctx context.Context, config pgconn.Config, options ...func(*pgx.ConnConfig)) (*pgx.Conn, error)
Connnect to local Postgres with optimised settings. The caller is responsible for closing the connection returned.
func DeleteAccessToken ¶
func DockerExecOnce ¶
func DockerExecOnce(ctx context.Context, containerId string, env []string, cmd []string) (string, error)
Exec a command once inside a container, returning stdout and throwing error on non-zero exit code.
func DockerImagePull ¶
func DockerRemove ¶
func DockerRemove(containerId string)
func DockerRemoveAll ¶
func DockerRunJob ¶
func DockerRunOnce ¶
Runs a container image exactly once, returning stdout and throwing error on non-zero exit code.
func DockerRunOnceWithConfig ¶
func DockerRunOnceWithStream ¶
func DockerStart ¶
func DockerStreamLogs ¶
func DockerStreamLogsOnce ¶
func FallbackLookupIP ¶
Performs DNS lookup via HTTPS, in case firewall blocks native netgo resolver.
func FormatRegion ¶
func FormatTime ¶
func FormatTimestamp ¶
func FormatTimestampVersion ¶
func GetCurrentTimestamp ¶
func GetCurrentTimestamp() string
func GetDebugLogger ¶
func GetDeclarativeDir ¶
func GetDeclarativeDir() string
func GetDenoPath ¶
func GetDockerIds ¶
func GetDockerIds() []string
func GetGitBranch ¶
func GetHostname ¶
func GetHostname() string
func GetLatestRelease ¶
GetLatestRelease queries the npm registry's latest dist-tag and returns a "v"-prefixed version string (for semver comparison with utils.Version).
func GetOrgBillingURL ¶
func GetPoolerConfig ¶
func GetPoolerConfigPrimary ¶
func GetRegistry ¶
func GetRegistry() string
func GetRegistryAuth ¶
func GetRegistryAuth() string
func GetRegistryImageUrl ¶
func GetServices ¶
func GetSupabase ¶
func GetSupabase() *supabase.ClientWithResponses
func GetSupabaseAPIHost ¶
func GetSupabaseAPIHost() string
func GetSupabaseDashboardURL ¶
func GetSupabaseDashboardURL() string
func GetSupabaseDbHost ¶
func GetSupabaseHost ¶
func InitConfig ¶
func InitConfig(params InitParams, fsys afero.Fs) error
func IsAgentMode ¶
func IsAgentMode() bool
IsAgentMode returns true if the CLI is being used by an AI agent. "yes" forces agent mode on, "no" forces it off, and "auto" (default) auto-detects based on environment variables.
func IsBranchNameReserved ¶
func IsDockerRunning ¶
func IsGitIgnored ¶
func IsLocalDatabase ¶
func IsPgDeltaEnabled ¶
func IsPgDeltaEnabled() bool
func MkdirIfNotExist ¶
func NewBackoffPolicy ¶
func NewBackoffPolicy(ctx context.Context) backoff.BackOffContext
func ProcessDiffOutput ¶
func ProcessPullOutput ¶
func ProcessPullOutput(out io.ReadCloser, p Program) error
func RemoveDuplicates ¶
func RemoveDuplicates[T comparable](slice []T) (result []T)
func RenderTable ¶
func RunEdgeRuntimeScript ¶
func RunEdgeRuntimeScript(ctx context.Context, env []string, script string, binds []string, errPrefix string, stdout, stderr *bytes.Buffer) error
RunEdgeRuntimeScript executes a TypeScript program inside the configured Edge Runtime container and streams stdout/stderr back to the caller.
func RunProgram ¶
func SetConnectSuggestion ¶
func SetConnectSuggestion(err error)
Sets CmdSuggestion to an actionable hint based on the given pg connection error.
func ShortContainerImageName ¶
func SuggestClaudePlugin ¶
func SuggestClaudePlugin() string
func SuggestUpgradeOnError ¶
func SuggestUpgradeOnError(ctx context.Context, projectRef, featureKey string, statusCode int) (orgSlug string, isGated bool)
SuggestUpgradeOnError checks if a failed API response is due to plan limitations by looking up the org's entitlements. Only sets CmdSuggestion when the entitlements API confirms the feature is gated (hasAccess == false). Returns the resolved org slug and true if a billing suggestion was shown (so callers can fire telemetry). Only checks on 4xx client errors; skips 2xx (success) and 5xx (server errors).
func ToDockerPath ¶
func ToPostgresURL ¶
func ToRealtimeEnv ¶
func ToRealtimeEnv(addr config.AddressFamily) string
func UpdateDockerIds ¶
func UpdateDockerIds()
func ValidateFunctionSlug ¶
Types ¶
type Console ¶
type Console struct {
IsTTY bool
// contains filtered or unexported fields
}
func NewConsole ¶
func NewConsole() *Console
func (*Console) PromptText ¶
PromptText asks for input using the label.
func (*Console) PromptYesNo ¶
PromptYesNo asks yes/no questions using the label.
type DenoScriptDir ¶
func CopyDenoScripts ¶
Copy Deno scripts needed for function deploy and downloads, returning a DenoScriptDir struct or an error.
type DiffDependencies ¶
type DiffDependencies struct {
Type string `json:"type"`
}
type DiffStream ¶
type DiffStream struct {
// contains filtered or unexported fields
}
func NewDiffStream ¶
func NewDiffStream(p Program) *DiffStream
func (DiffStream) Collect ¶
func (c DiffStream) Collect() ([]byte, error)
func (DiffStream) Stderr ¶
func (c DiffStream) Stderr() io.Writer
func (DiffStream) Stdout ¶
func (c DiffStream) Stdout() io.Writer
type InitParams ¶
type Profile ¶
type Profile struct {
Name string `mapstructure:"name" validate:"required"`
APIURL string `mapstructure:"api_url" validate:"required,http_url"`
DashboardURL string `mapstructure:"dashboard_url" validate:"required,http_url"`
DocsURL string `mapstructure:"docs_url" validate:"omitempty,http_url"`
ProjectHost string `mapstructure:"project_host" validate:"required,hostname_rfc1123"`
PoolerHost string `mapstructure:"pooler_host" validate:"omitempty,hostname_rfc1123"`
AuthClientID string `mapstructure:"client_id" validate:"omitempty,uuid4"`
StudioImage string `mapstructure:"studio_image"`
ProjectRegions []api.V1CreateProjectBodyRegion `mapstructure:"regions"`
}
var CurrentProfile Profile
type Program ¶
An interface describing the parts of BubbleTea's Program that we actually use.
func NewProgram ¶
func NewProgram(model tea.Model, opts ...tea.ProgramOption) Program
type ProgressMsg ¶
type ProgressMsg *float64
type PromptItem ¶
PromptItem is exposed as prompt input, empty summary + details will be excluded.
func PromptChoice ¶
func PromptChoice(ctx context.Context, title string, items []PromptItem, opts ...tea.ProgramOption) (PromptItem, error)
Prompt user to choose from a list of items, returns the chosen index.
func (PromptItem) Description ¶
func (i PromptItem) Description() string
func (PromptItem) FilterValue ¶
func (i PromptItem) FilterValue() string
func (PromptItem) Title ¶
func (i PromptItem) Title() string
type StatusWriter ¶
type StatusWriter struct {
Program
}