-
Notifications
You must be signed in to change notification settings - Fork 240
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
feat(se): allow model/table renaming in postgres and sqlserver #4914
base: main
Are you sure you want to change the base?
feat(se): allow model/table renaming in postgres and sqlserver #4914
Conversation
Is that guaranteed? Some thoughts after thinking about this for not too long, so potentially irrelevant/wrong:
|
CodSpeed Performance ReportMerging #4914 will not alter performanceComparing Summary
|
@janpio thanks for commenting on this.
|
Heads up: We had an internal conversation that we probably would want to offer this to our users as a choice, via an interactive prompt, instead of using some heuristics to decide for them. But we also realize that implementing this prompt is probably quite a big lift, as it would possibly completely need to change how Prisma CLI and Schema Engine communicate during Do you think that makes sense? |
I understand that predicting renames with certainty is not a trivial problem. I achieved that for Postgres and SQLServer only because those databases support names for primary key constraints, which helped in safely finding tables that are renamed. But in order to enable the feature for other databases, and furthermore enabling something like column renames, there are limitations that prevent us from knowing exactly the user's intent and making the decision for them. So, even though it would be a big change on how the client and schema engine communicate, it makes a ton of sense to reach for an interactivity. Thanks |
if a developer wants to rename a model/table, Prisma Migrate currently diffs the two models and generates a migration to drop the previous table and create a new table.
This PR's purpose is to introduce a mechanism that knows if a table is renamed and for Prisma to generate a migration that renames the table properly. To do so, the renamed table must be identifiable with high certainty.
For databases that support naming primary key constraints (Postgres, SQLServer), we can check if the table is being renamed by looking at the key. If the key is the same, the table is the same.
So, this feature would apply to those supported databases, for now, and for cases when primary key is not given a specific name, the default behavior of dropping and recreating the table would apply.
Example:
Renaming table
User
toPerson
, will simply, as always, drop tableUser
and create tablePerson
. But:By setting a name to the primary key of the table, renaming table
User
toPerson
, will generate the following query:Related issues: