SeaQL / SeaQL/sea-orm

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

Open
#2,584 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area:schema
Dominant language
Rust
Stars
9.9k
Forks
734
Avg merge
6h 36m
Merged PRs (30d)
8

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the sea-orm-cli generate entity command and reproduce the failure using the public and custom_schema database schemas described in the issue. Trace PostgreSQL type reflection for the cross-schema enum and compare generated entities for each schema. Done means custom_schema generation recognizes public.status_type and emits correct schema-qualified references or imports without failing.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, rust
Domain
cli, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.