Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Atlas migrations add extra unique index on primary keys #2401

Closed
2 tasks done
ivanvanderbyl opened this issue Mar 15, 2022 · 2 comments · Fixed by #2425
Closed
2 tasks done

Atlas migrations add extra unique index on primary keys #2401

ivanvanderbyl opened this issue Mar 15, 2022 · 2 comments · Fixed by #2425

Comments

@ivanvanderbyl
Copy link
Contributor

ivanvanderbyl commented Mar 15, 2022

After switching to Atlas for migrations, the first migration added an additional unique index on all id fields, even though there is already a primary key index.

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Switching to Atlas creates migrations such as:

CREATE UNIQUE INDEX "users_id_key" ON "users" ("id");

When users already has a primary key index:

Indexes:
    "users_pkey" PRIMARY KEY, btree (id)

Resulting in:

                                         Table "public.users"
       Column       |            Type             | Collation | Nullable |          Default
--------------------+-----------------------------+-----------+----------+----------------------------
 id                 | character varying           |           | not null |
Indexes:
    "users_pkey" PRIMARY KEY, btree (id)
    "users_id_key" UNIQUE, btree (id)

Expected Behavior 🤔

Atlas should recognise the primary key index and not create an additional index.

Steps to Reproduce 🕹

Usual Ent setup using custom IDs as strings.

func (User) Fields() []ent.Field {
	return []ent.Field{
		field.String("id").
			MaxLen(31).
			NotEmpty().
			Unique().
			DefaultFunc(UserIDFunc).
			Immutable(),
        ...
}

Your Environment 🌎

Tech Version
Go 1.18.rc1
Ent master
Atlas master
Database Postgres
@hehex9
Copy link

hehex9 commented Mar 23, 2022

facing the same issue, any workaround?

@a8m
Copy link
Member

a8m commented Mar 24, 2022

Thanks for reporting this @ivanvanderbyl and @hehex9

Fixed with #2425

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

Successfully merging a pull request may close this issue.

3 participants