verbb / cp-nav

Control Panel Nav is a Craft CMS plugin to help manage your Control Panel navigation.
MIT License
130 stars 11 forks source link

cp-nav tables don't get removed after uninstalling / removing plugin after applying project-config changes on production #81

Closed mdominguez closed 2 years ago

mdominguez commented 3 years ago

Description cp-nav tables on the production database don't get removed after uninstalling / removing plugin and after applying project-config changes on production. If I remove these tables manually I get a migration error so that's not an option too..

When I try to reinstall the plugin the old cp-nav tables don't get overwritten with the fresh installed ones, so if you could just help us out here what to undertake in order to remove all of the cp-nav stuff in our production database, that would be great :)

Steps to reproduce Updated from Craft 3.3 to 3.5 and the plugin 2.X to 3.X

Additional info

Additional context

engram-design commented 3 years ago

Just so I'm clear, are you uninstalling the plugin locally, and then pushing to production, to let project config take over? Or are you uninstalling the plugin on production directly?

In either case, does the plugin uninstall correctly without errors? As in - it shows as disabled on the plugins page.

If you have allowAdminChanges set to false on production, you won't be able to check the plugins page, so I might recommend you turn that on temporarily so you can double check on production everything is okay.

I'm not sure what you mean by a migration error when you remove the tables manually? If the plugin is uninstalled correctly, deleting the tables shouldn't be an issue. If it is, it sounds like the plugin isn't uninstalled correctly.

mdominguez commented 3 years ago

Yep I'm uninstalling / installing locally, then deploying to production and let project-config sync/apply the cp nav settings I setup locally, unfortunately without the desired result...

If I check with allowAdminChanges set to false, the plugin doesn't even get activated anymore, while locally it's definitely activated...

mdominguez commented 3 years ago

Screenshot of the tables locally / production => screenshot

engram-design commented 3 years ago

Hmm, so just to confirm, the plugin on production is correctly uninstalled? I have just tested with this normal workflow setup, and can't reproduce (tables and project config get dropped correctly). I'll continue looking into it.

juddlyon commented 3 years ago

I have the same issue (Craft 3.6.17, CP Nav 3.0.16). Control Panel Navigation plugin has been removed in production manually via the control panel. It no longer shows up the in the UI and is not present when querying select * from plugins.

However, the following DB tables are left behind:

I've had a lot of issues with CP Nav and the same workflow @mdominguez describes:

  1. install and configure nav items locally, which writes to config/project
  2. deploy to production which runs project-config/apply
  3. the plugin does not install or show items in production but I can see it under plugins

This flow is required, otherwise you wipe out your navigation on each deployment. My hunch is that a previous upgrade migration possibly failed?

engram-design commented 3 years ago

Hmmm, I'm not sure how much more explicit I can get in the uninstall migration:

https://github.com/verbb/cp-nav/blob/ae3843c82779533a041e19653fd27b3b1baee334/src/migrations/Install.php#L74-L84

Which removed all database tables and project config data when uninstalling.

The project-config/apply on production should run that migration. I'm not sure what's going on, as testing on a few environments (staging/local/production) this is working correctly.

Thanks for confirming though, I'll have to keep digging. All I can think of is that somewhere along the line, your project config has gotten confused (which happens to me on projects a lot and has become out of sync).

juddlyon commented 3 years ago

@engram-design Thanks for the reply. No clue how I got it to this state but I got it sorted.

The uninstall code was never running but because the plugin wasn't actually installing (presumably due to the tables already existing). Since this was happening via Project Config I didn't get any insight.

Composer would add the package so it'd show up in the Control Panel, but only with the INSTALL and REMOVE options. REMOVE would get rid of the code package but wasn't running your removeTables and dropProjectConfig.

The fix for me in case anybody else does something similar (back everything up of course):

  1. Drop tables (see SQL below)
  2. Install CP Nav locally and configure links
  3. Deploy and let the sweet magic of Project Config do the rest
# disable foreign keys so you can drop tables
SET FOREIGN_KEY_CHECKS = 0; 

# drop zombie tables
DROP TABLES cpnav_layout;
DROP TABLES cpnav_navigation;
DROP TABLES cpnav_pending_navigations;

# enable foreign keys
SET FOREIGN_KEY_CHECKS = 1; 

# check your work
SELECT @@GLOBAL.foreign_key_checks, @@SESSION.foreign_key_checks;
engram-design commented 3 years ago

Thanks @juddlyon

engram-design commented 2 years ago

Should be fixed in 4.0.0-beta.2 for Craft 4.