Add helpers for plugin install migrations with existing database tables #10827
-
On the rare occasion, when a plugin isn't uninstalled properly, the database tables created in the install migration stick around. This can happen for a variety of reasons, including:
For the last item, that can happen pretty commonly. For example, someone tries out a plugin by installing it, but doesn't like it. They forget to uninstall it properly (running the uninstall migrations) and while the files are removed, Craft still considers it installed. Months/years down the track, they install the plugin again and they'll be smacked with an error about existing tables. We have a few options as plugin developers in our install migrations:
We can't rely on potentially stale existing database tables, so we need to start fresh. But then we also might lose any existing data, so that's dangerous. Commerce doesn't even handle this. So in an effort to provide some best-practices for plugin developers, I might propose Craft provide a way to handle this. As I've mentioned, we can of course handle this as plugin developers, and for those that need special handling of existing tables are free to do so. But for 99% of plugins out there, I think some sane defaults will help end users frustrated with install issues from plugin developers who might not be aware of this potential edge-case. Some proposals: Adding a
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Just added a new I’ve also drafted a PR for Commerce to start taking advantage of this, once Craft 4 Beta 4 goes out. (craftcms/commerce#2765) |
Beta Was this translation helpful? Give feedback.
Just added a new
Migration::archiveTableIfExists()
method, for the next release. This will need to be called in addition tocreateTable()
(9a30d8b).I’ve also drafted a PR for Commerce to start taking advantage of this, once Craft 4 Beta 4 goes out. (craftcms/commerce#2765)