Skip to content

sea-orm-cli generate entity fails with cross-referenced types from other schemas #2584

@crmilsap

Description

@crmilsap

Description

Entity Generation Fails with Cross-Schema Type References

Steps to Reproduce

  1. Create a database with the following schema:
-- Create enum type in public schema
CREATE TYPE public.status_type AS ENUM ('active', 'inactive', 'pending');

-- Create custom schema
CREATE SCHEMA custom_schema;

-- Create table in custom schema that uses the enum from public schema
CREATE TABLE custom_schema.items (
    id SERIAL PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    status public.status_type NOT NULL
);
  1. Run sea-orm-cli to generate entities for the public schema (works fine):
sea-orm-cli generate entity \
  -u "postgres://user:pass@localhost/dbname" \
  -o "./entities/public" \
  --database-schema public
  1. Run sea-orm-cli to generate entities for the custom schema (fails):
sea-orm-cli generate entity \
  -u "postgres://user:pass@localhost/dbname" \
  -o "./entities/custom" \
  --database-schema custom_schema

Error Message

error returned from database: type "status_type" does not exist

Expected Behavior

The CLI should correctly recognize that status_type exists in the public schema and generate proper imports or references to it when generating entities for the custom schema.
Ideally we could pass a comma separated list into the --database-schema arg.

Actual Behavior

  1. The CLI fails to recognize types from other schemas, causing generation to fail with a "type does not exist" error.
  2. When the enum is moved out of the public statement. The reflection fails to prepend the schema to the name field in the sea_orm attribute macro.

Reproduces How Often

Always

Workarounds

Duplicate the enum across schemas gets passed the reflection, but I've run into issues with insertion.

Versions

sea-orm: 1.1.4
postgres: 16

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-schemaArea: schema discovery

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions