Skip to content

Prioritize current schema for pg type generation #939

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yilinjuang
Copy link

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

If multiple schemas have enum types with the same name, the generated enum types all use the same schema, which is the first schema returned by pgMeta.types.list().

export type Database = {
  schema_1: {
    Tables: {
      table_name: {
        Row: {
          type: Database["schema_1"]["Enums"]["some_enum"];
        };
      };
    };
    Enums: {
      some_enum: "some_value" | "some_other_value";
    };
  };
  schema_2: {
    Tables: {
      table_name: {
        Row: {
          // schema_1 is used here
          type: Database["schema_1"]["Enums"]["some_enum"];
        };
      };
    };
    Enums: {
      some_enum: "some_value" | "some_other_value";
    };
  };
};

What is the new behavior?

If the current/self schema has the enum type, generated enum type will use the current schema instead of the first schema.

export type Database = {
  schema_1: {
    Tables: {
      table_name: {
        Row: {
          type: Database["schema_1"]["Enums"]["some_enum"];
        };
      };
    };
    Enums: {
      some_enum: "some_value" | "some_other_value";
    };
  };
  schema_2: {
    Tables: {
      table_name: {
        Row: {
          // schema_2 is used here
          type: Database["schema_2"]["Enums"]["some_enum"];
        };
      };
    };
    Enums: {
      some_enum: "some_value" | "some_other_value";
    };
  };
};

Additional context

Add any other context or screenshots.

@yilinjuang yilinjuang requested review from a team as code owners May 2, 2025 14:00
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