netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Try NetBox Cloud free: https://netboxlabs.com/free-netbox-cloud/
http://netboxlabs.com/oss/netbox/
Apache License 2.0
16.17k stars 2.59k forks source link

Add guidance to remove plugin entries from django_migrations table in plugins/removal.md #16539

Closed dberg918 closed 3 months ago

dberg918 commented 5 months ago

Change Type

Addition

Area

Plugins

Proposed Changes

Recently I upgraded my Netbox instance to 4.x and had to remove the netbox-topology-views plugin since the beta was not ready yet. I followed the instructions in the documentation to remove the plugin from the configuration and to drop the tables it created in the netbox database and everything seemed fine.

After the beta version of the plugin was released last week, I decided to try it out. The installation worked fine, but when running the manage.py migrate netbox_topology_views command, it did not repopulate the tables in the netbox database. As a result, the plugin threw errors complaining that the requisite tables did not exist in the database, and running upgrades similarly failed with an identical error message. Eventually, I figured out this was because there were still entries for netbox_topology_views in my django_migrations table. After I removed these, the migrations worked correctly and populated the database with the necessary tables.

I'd like to propose adding a small section to the end of the "Removing a Plugin" section that includes deleting entries in the django_migrations table. I've written a sample below:


Also check for entries in the django_migrations table using the same pluginname:

netbox=> select * from django_migrations where app = 'pluginname';
id  |    app     |          name           |            applied
----+------------+-------------------------+-------------------------------
100 | pluginname | 0001_initial            | 1970-01-01 00:00:00.000000-05
101 | pluginname | 0002_pluginname_options | 1970-01-01 00:00:00.000001-05
(2 rows)

Drop the entries in the django_migrations table if they exist:

netbox=> delete from django_migrations where app = 'pluginname';
a084ed22 commented 5 months ago

If your issue is related only to plugins not yet supporting netbox 4.x, there's no need to delete the data structures they have in the database, it's sufficient to comment out the plugin-related content in configuration.py. These instructions may however be useful if you want to uninstall the plugin and purge its contents from the database.

dberg918 commented 5 months ago

I had to re-read your comment a few times to understand your point. Yes, if you just want to remove a plugin temporarily while you wait for it to support the new version, commenting it out in configuration.py is enough. However, the documentation does not delineate between removing a plugin temporarily and removing a plugin permanently.

Either way, I think if it provides instructions on how to drop a plugin's tables from the database, it should also provide instructions to remove its entries from the django_migrations table since they go hand-in-hand. Otherwise, the plugin will be broken if the user ever decides to re-install it.

dberg918 commented 4 months ago

I can submit a pull request, but I need to have this issue assigned to me first and it looks like I can't do it myself. @arthanson would you be able to assist?

dberg918 commented 3 months ago

@peteeckel actually raised the same issue with #16748 and got a fixed merged last month, so this can be closed.