Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: automatically set default schema env var for type generation #3243

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

bug-author
Copy link

What kind of change does this PR introduce?

This PR lets the CLI automatically detect when exactly one non‑public schema is provided and sets the environment variable PG_META_GENERATE_TYPES_DEFAULT_SCHEMA accordingly.

What is the current behavior?

Currently, when running supabase gen types, the CLI passes the schema flags directly to postgres‑meta without automatically setting a default schema. This results in the generated TypeScript file always defaulting to the "public" alias:

export type PublicSchema = Database[Extract<keyof Database, "public">]

Even if a non‑public schema is specified (for example, --schema robo), helper types (like Tables<"test_table">) incorrectly reference the public schema.

Relevant issues:
#3061
#3146

What is the new behavior?

The CLI now automatically checks if exactly one schema is provided (and if that schema is not "public"). If so, it sets the environment variable PG_META_GENERATE_TYPES_DEFAULT_SCHEMA to that schema's name. This allows postgres‑meta to generate a default alias based on the provided schema (for example, for "robo", the generated file will include):

export type DefaultSchema = Database[Extract<keyof Database, "robo">]
export type DefaultSchemaOrPublic = DefaultSchema

In single‑schema mode, shorthand type references (like Tables<"test_table">) correctly resolve to the non‑public schema. In multi‑schema scenarios, the variable is not set, and users must explicitly specify the schema for non‑public tables.

Additional context

Corresponding postgres-meta PR

@coveralls
Copy link

coveralls commented Mar 3, 2025

Pull Request Test Coverage Report for Build 13640816547

Details

  • 13 of 17 (76.47%) changed or added relevant lines in 1 file are covered.
  • 8 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.05%) to 57.91%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/gen/types/types.go 13 17 76.47%
Files with Coverage Reduction New Missed Lines %
internal/debug/postgres.go 3 64.86%
internal/gen/keys/keys.go 5 12.9%
Totals Coverage Status
Change from base Build 13635933861: -0.05%
Covered Lines: 7830
Relevant Lines: 13521

💛 - Coveralls

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.

2 participants