Skip to content
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

Command to remove unused switches/flags #492

Open
cristianowa opened this issue Nov 29, 2023 · 4 comments
Open

Command to remove unused switches/flags #492

cristianowa opened this issue Nov 29, 2023 · 4 comments

Comments

@cristianowa
Copy link

In our usage of django-waffle when switches are removed they often are left in at least one environment database without any meaningful use.

The cost it self is irrelevant for a DB, but checking for active switches (usually debugging a production issue) get more complex overtime.

I have made this script to clean the switches and executed it on Django shell.

from waffle.models import *
switches = Switch.objects.all()

from subprocess import getoutput
from subprocess import getstatusoutput as cmd

print("name", "is_active", "created", "modified")
for switch in switches:
    switch_not_found, _ = cmd("grep -ri {switch.name} *")
    if switch_not_found:
       print(switch.name, switch.is_active, switch.created, switch.modified)
       switch.delete()

I saw there is already a command for deleting data.

My proposal here is to create a command like waffle_remove_unused with options for switches, flags and samples, and also having a dry-run (just printing what would be deleted).

If that is OK I would be glad to work on a PR for it.

The first thing being changing that grep to a Python implementation. Second is to make this generic to Samples and Flags as well.

@clintonb
Copy link
Collaborator

clintonb commented Dec 1, 2023

A pull request is welcome. I, personally, would be hesitant to use such a command due to lack of trust. It's far simpler for me to grep/search the code myself than hope someone else's command does the right thing. But, that's me.

@cristianowa
Copy link
Author

cristianowa commented Dec 6, 2023

Got it @clintonb, thanks for the feedback. I think the command should not be used in all cases, but in some it makes sense. In our case we have a system with hundreds of feature flags, and a lot of them were forgotten/lost in the process of removal.

I will work on the code and will open the PR as soon as I can.

@cristianowa
Copy link
Author

@clintonb When you have the time, please share you thoughts on #493 . 🙂

@levimoore1992
Copy link

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants