Skip to content

fix(cli): generate non-TypeScript types from project refs#5622

Open
avallete wants to merge 7 commits into
developfrom
avallete/cli-1812-python-type-generation-with-project-id-fails-and-db-url
Open

fix(cli): generate non-TypeScript types from project refs#5622
avallete wants to merge 7 commits into
developfrom
avallete/cli-1812-python-type-generation-with-project-id-fails-and-db-url

Conversation

@avallete

@avallete avallete commented Jun 18, 2026

Copy link
Copy Markdown
Member

What changed

  • Lets legacy supabase gen types --project-id generate Go, Swift, and Python types by resolving a temporary database connection and running pg-meta.
  • Keeps TypeScript project-ref generation on the Management API typegen endpoint, while non-TypeScript project-ref flows use the project database host plus a temporary login role.
  • Updates side-effect docs and integration coverage for project-ref type generation across TypeScript, Go, Swift, and Python.
  • Adds e2e coverage for tokenless local typegen and an env-gated live remote project matrix across all supported typegen languages.

Why

Python type generation with --project-id failed before it could reach pg-meta, and the first fix used the preview-branch config endpoint. Production project refs return 404 Preview branch not found from that endpoint because /v1/branches/{ref} is branch-only.

Non-TypeScript type generation is still pg-meta-based, so project-ref flows need to construct a live database connection instead of calling the TypeScript-only typegen endpoint or asking the user to provide --db-url.

Reviewer context

Non-TypeScript project-ref generation still requires Docker because it continues to use pg-meta. The change is limited to how the CLI resolves the database connection for project refs: it fetches the project database host and creates a temporary login role rather than reading or storing the project's database password.

The live remote e2e matrix is skipped unless SUPABASE_TYPEGEN_E2E_REMOTE=1, SUPABASE_TEST_PROJECT_REF, and SUPABASE_ACCESS_TOKEN are set. The local e2e matrix runs without a token and points the API profile at an unreachable local URL to catch accidental Management API usage on the --local path.

Closes CLI-1812

@avallete avallete changed the title Fix project-ref type generation for non-TypeScript languages in CLI-1812 fix(cli): generate non-TypeScript types from project refs Jun 18, 2026
@avallete avallete marked this pull request as ready for review June 19, 2026 10:10
@avallete avallete requested a review from a team as a code owner June 19, 2026 10:10
@github-actions

Copy link
Copy Markdown

Supabase CLI preview

npx --yes https://pkg.pr.new/supabase/cli/supabase@6314b35001f22686938e5455351f0e4317876a91

Preview package for commit 6314b35.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6314b35001

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +275 to +279
host: target.host,
port: target.port,
probeHost: target.host,
probePort: target.port,
networkMode: "host",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Route remote pg-meta through the linked DB resolver

For linked/project-ref non-TypeScript generation on an IPv4-only network, this always points pg-meta at project.database.host. The existing linked DB resolver treats an unreachable direct host as a supported case and falls back to the Supavisor pooler (apps/cli/src/legacy/shared/legacy-db-config.layer.ts:385-404, with the IPv6 error documented at legacy-db-config.errors.ts:66-70); bypassing it here means supabase gen types --project-id ... --lang go|swift|python fails during the TLS probe/container run instead of using the pooler for those projects.

Useful? React with 👍 / 👎.

@@ -0,0 +1 @@
{"ref":"hhrqlmthvbnwvlawqnwi","name":"rere","organization_id":"rnwamzlptflscprylent","organization_slug":"rnwamzlptflscprylent"} No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove the committed linked-project cache

This commits a machine-local Supabase linked-project cache under the repo root, including a real project ref/name/org id. The legacy analytics layer reads <cwd>/supabase/.temp/linked-project.json when commands run from the repository root, so this can leak workspace-specific project metadata into the repo and misattribute local command telemetry to that project.

Useful? React with 👍 / 👎.

Comment on lines +258 to +260
const project = yield* api.v1
.getProject({ ref: projectRef })
.pipe(Effect.catch(mapProjectDatabaseHostError));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fall back to branch config for preview branch refs

When --linked or --project-id points at a preview branch, getProject({ ref }) returns 404; the link handler already treats that 404 as the branch case (apps/cli/src/legacy/commands/link/link.handler.ts:36-49). Mapping the 404 here as a fatal project-database-config error means supabase gen types --project-id <branch-ref> --lang go|swift|python cannot reach pg-meta for linked branch projects, even though the branch config endpoint exposes the branch DB host/port for this scenario.

Useful? React with 👍 / 👎.

Effect.gen(function* () {
const api = yield* platformApi.make;

if (lang !== "typescript") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Allow pg-meta flags on project-ref typegen

Now that this branch runs pg-meta for project refs, the earlier mutual-exclusion checks still reject the pg-meta-only flags before this path can use them. For example, supabase gen types --project-id <ref> --lang swift --swift-access-control public fails up front, so remote Swift generation is stuck with internal access control; the same issue prevents raising --query-timeout or using v9 compatibility for large/legacy remote schemas.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant