Skip to content

Prioritize current schema for pg type generation #939

New issue

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

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

Already on GitHub? # to your account

Merged
merged 2 commits into from
May 11, 2025

Conversation

yilinjuang
Copy link
Contributor

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
@coveralls
Copy link

Pull Request Test Coverage Report for Build 14955777882

Details

  • 88 of 90 (97.78%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 76.041%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/server/templates/typescript.ts 88 90 97.78%
Totals Coverage Status
Change from base Build 14904124416: 0.2%
Covered Lines: 5156
Relevant Lines: 6698

💛 - Coveralls

Copy link
Member

@avallete avallete left a comment

Choose a reason for hiding this comment

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

Looks good, thank's for your contribution !

@avallete avallete merged commit 1083973 into supabase:master May 11, 2025
5 checks passed
@yilinjuang
Copy link
Contributor Author

Thanks @avallete. When can we release this? I'd love to start using it.

@avallete
Copy link
Member

My bad, I wrongly merged without creating a commit that follow the conventional commit which prevented the CD to create and push a new release with those changes.

Should be available once this: #939 get merged.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants