prisma1-upgrade icon indicating copy to clipboard operation
prisma1-upgrade copied to clipboard

upgrade cli does not distinguish that a field is ENUM and not a MEDIUMTEXT

Open omar-dulaimi opened this issue 4 years ago • 4 comments

Hello,

Our datamodel has a lot of ENUM type fields, some the cli were able to identify as such, but the rest were identified as MEDIUMTEXT.

Manually changing the SQL queries to the correct format, followed by introspection again did not remove the suggestion; it actually still showed that fields with MEDIUMTEXT type needed a default value, although I had already taken care of that.

omar-dulaimi avatar Feb 20 '21 10:02 omar-dulaimi

please update on this issue still I have facing this issue.

da201501245 avatar Apr 12 '22 06:04 da201501245

Can you show an example of a Prisma 1 schema and the corresponding SQL schema that has this problem?

janpio avatar Apr 12 '22 15:04 janpio

Thanks for a prompt response. please find here Prisma 1 schema

type User {
	id: ID! @unique
	email: String
	userStatus: UserStatus @default(value: "PENDING")
	userStatusUpdatedAt: DateTime
}

enum UserStatus {
	APPROVED
	BLOCKED
	ARCHIVED
	REJECTED
	PENDING
	REVOKED
}

As you can see here userStatus in User is enum.

So Prisma upgrade CLI given SQL statement for making PRISMA 2 compatible is,

ALTER TABLE `User` CHANGE `userStatus` `userStatus` ENUM('APPROVED', 'BLOCKED', 'ARCHIVED', 'REJECTED', 'PENDING', 'REVOKED') ;
ALTER TABLE `User` CHANGE `userStatus` `userStatus` MEDIUMTEXT  DEFAULT 'PENDING';

So if we run the above script in a database then it will again convert this field into MEDIUMTEXT from ENUM. so ideal script for these changes should be this,

ALTER TABLE `User` CHANGE `userStatus` `userStatus` ENUM('APPROVED', 'BLOCKED', 'ARCHIVED', 'REJECTED', 'PENDING', 'REVOKED') DEFAULT 'PENDING' ;

also one more point for MySQL 5.7 version below script showing error BLOB, TEXT, GEOMETRY or JSON column 'userStatus' can't have a default value, due to TEXT type column does not support default value in 5.7 version MySQL.

ALTER TABLE `User` CHANGE `userStatus` `userStatus` MEDIUMTEXT  DEFAULT 'PENDING';

also, MySQL version 8.0 also has not run the above script we need to slightly modify the above script in order to run in the database, here's updated script,

ALTER TABLE `User` CHANGE `userStatus` `userStatus` MEDIUMTEXT  DEFAULT ('PENDING');

da201501245 avatar Apr 13 '22 10:04 da201501245

What does the Prima 1 created SQL look like before you use the upgrade CLI at all?

janpio avatar Apr 13 '22 11:04 janpio