Skip to content

Duplicate Postgres enums across schemas #142

@JayTee42

Description

@JayTee42

Description

When generating entities through sea-orm-cli for a Postgres database, I realized that my enums in sea_orm_active_enums.rs have duplicated members:

pub enum Test {
    #[sea_orm(string_value = "A")]
    A,
    #[sea_orm(string_value = "A")]
    A,
    #[sea_orm(string_value = "B")]
    B,
    #[sea_orm(string_value = "B")]
    B,
}

Obviously, this blocks the project from compiling. The root cause seems to be that my DB contains two distinct schemas with the same enums. When I delete one of the schemas and try again, the duplicates are gone.

Steps to Reproduce

  1. Create a Postgres DB with two schemas s0 and s1.
  2. Create enums with the same name and members in both schemas (e.g. s0.Test and s1.Test).
  3. Generate sea-orm bindings for either s0 or s1.

Expected Behavior

The generated enums are restricted to the chosen schema and contain no duplicate members.

Actual Behavior

The generated enums are mixed up across schemas.

Additional Information

I suspect that the problem originates from sea_schema::postgres::query::enumeration::SchemaQueryBuilder::query_enums:

pub fn query_enums(&self) -> SelectStatement {

The query in this method is not restricted to a schema. A possible solution:

  • Add a join to pg_namespace on pg_namespace.oid = pg_type.typnamespace
  • Filter by pg_namespace.nspname = <schema>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions