Skip to content

redundant unique index on entity-first approach #2873

@chungwong

Description

@chungwong

Description

Discord Ref
With the new entity-first approach, we can add unique as below

#[sea_orm(unique, column_type = "Text")]
pub url: String,

I found it will generate two indexes, at least on Postgres

                                        Table "public.url"
   Column    |           Type           | Collation | Nullable |             Default
-------------+--------------------------+-----------+----------+----------------------------------
 id          | bigint                   |           | not null | generated by default as identity
 url         | text                     |           | not null |

Indexes:
    "url_pkey" PRIMARY KEY, btree (id)
    "idx-url-url" UNIQUE, btree (url)
    "url_url_key" UNIQUE CONSTRAINT, btree (url)

As you can see, it generated two indexes for UNIQUE property. I seeked help from the PG discord channel and asked if it is necessary and the adivce I got back was hinting it could be a mistake to have both indexes and UNIQUE CONSTRAINT is more "CORRECT", althought the difference is minimal.

Expected Behavior

It should use just UNIQUE CONSTRAINT

Actual Behavior

 "idx-url-url" UNIQUE, btree (url)

is redundant

Versions

sea-orm v2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions