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

Migrate tries to drop + recreate column when changing type from TEXT -> CITEXT (Postgres) #7536

Closed
sdnts opened this issue Jun 8, 2021 · 1 comment · Fixed by prisma/prisma-engines#2058
Assignees
Labels
kind/improvement An improvement to existing feature and code. team/schema Issue for team Schema. topic: prisma migrate dev CLI: prisma migrate dev
Milestone

Comments

@sdnts
Copy link
Contributor

sdnts commented Jun 8, 2021

Reproduction

  1. Start with this schema (Postgres):
model User {
  id String @id @default(cuid())
  email String
}
  1. Create a migration using migrate dev. This is the migration that gets created:
-- CreateTable
CREATE TABLE "user" (
    "id" SERIAL NOT NULL,
    "email" TEXT NOT NULL,

    PRIMARY KEY ("id")
);
  1. Then change the schema to:
model User {
  id String @id @default(cuid())
  email String @db.Citext
}
  1. Create the CITEXT extension manually:
CREATE EXTENSION IF NOT EXISTS citext WITH SCHEMA public;
  1. Run migrate dev again, this is the second migration that is created:
/*
  Warnings:

  - Changed the type of `email` on the `user` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.

*/
-- AlterTable
ALTER TABLE "user" DROP COLUMN "email",
ADD COLUMN     "email" CITEXT NOT NULL;

Expectation

Only the column type is ALTERed.

@janpio janpio transferred this issue from prisma/prisma-engines Jun 8, 2021
@janpio janpio added the team/schema Issue for team Schema. label Jun 8, 2021
@Jolg42 Jolg42 added kind/improvement An improvement to existing feature and code. process/candidate topic: prisma migrate dev CLI: prisma migrate dev labels Jun 9, 2021
@tomhoule tomhoule added this to the 2.26.0 milestone Jun 17, 2021
@tomhoule
Copy link
Contributor

Taking this in to confirm quickly if a cast is possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/improvement An improvement to existing feature and code. team/schema Issue for team Schema. topic: prisma migrate dev CLI: prisma migrate dev
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants