Improve handling of unexecutable migrations in Prisma Migrate #5163
Labels
kind/improvement
An improvement to existing feature and code.
team/schema
Issue for team Schema.
topic: migrate
Milestone
Problem
In certain cases, Prisma Migrate can't fully figure out how to make a certain migration happen.
Example: adding a new required field without a default value to a table with pre-existing records.
Prisma Migrate would usually create the column with the not-null constraint, but since there is no default value this would fail. Prisma Migrate currently fails with an error message.
Example of error message:
Problems:
--create-only
is an option in this case.--create-only
to at least create a migration file, even if the migration will fail to run without manually modifying to deal with the underlying issuesPossible Solutions
For the specific example described above there are multiple ways to migrate the database schema:
Approach 1 can be addressed by the developer but may not always be a desirable or feasible solution depending on the use case
Approach 2 can can be implemented by the developer in the migration file, but Prisma Migrate errors and does not generate any migration file unless using
--create-only
. The migration script currently renders a single statement to add the column with the constraint and and to make the migration work the developer will need to do heavy editing to turn this into several steps and be able to intertwine the migration themselves.Approach 3 Might be a simpler approach from the user's POV and adding an UPDATE statement to the first migration even if non-trivial requires less fiddling than in solution 2.
Suggested solution
The text was updated successfully, but these errors were encountered: