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

Support for multiple / non-default database #35

Open
farialima opened this issue Feb 2, 2022 · 2 comments
Open

Support for multiple / non-default database #35

farialima opened this issue Feb 2, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@farialima
Copy link

farialima commented Feb 2, 2022

  • Django Scrubber version: 0.6
  • Django version: All
  • Python version: All
  • Operating System: All

Description

I use multiple databases in my app -- and Django-scrubber only scrubs the default one.

What I Did

My app uses 3 DBs, with the same models, for different customers, so my settings (in dev -- copied from prod) have this:

DATABASES = {
    key: {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': f'devdb-${key}',
        'USER': 'test',
        'PASSWORD': os.getenv("DB_TEST_PASSWORD"),
        'HOST': 'db.mydomain.com',
        'PORT': '5432',
    } for key in ['default', 'customer1', 'customer2', 'customer3']
}

I'd like to scrub the 3 customer DBs, but Django-scrubber doesn't let me do that. It would be nice to have a --database <db> option, or --all-databases

A workaround is to add this in my manage.py's main() function

    if len(sys.argv) > 1 and sys.argv[1] == "scrub_data":
        if "--database" in sys.argv:
            from django.conf import settings

            database_index = sys.argv.index("--database")
            del sys.argv[database_index]
            settings.DATABASES["default"] = settings.DATABASES[sys.argv[database_index]]
            print(f"Scrubbing database {sys.argv[database_index]}")
            del sys.argv[database_index]

then I execute:
./manage.py scrub_data --database customer1, etc.

it's working well, but it's a little ugly... would be nicer to have a clean support in django-scrubber :)

@lociii
Copy link
Member

lociii commented Jul 11, 2022

Hey François,

sorry for the very very late response. Would you mind submitting a pull request with the necessary changes to support a database selection out of the box?

Thanks, Jens

@lociii lociii added the enhancement New feature or request label Jul 11, 2022
@farialima
Copy link
Author

I've started to implement on, it's not finished -- and I won't have time to put more effort on it. But maybe someone will finish it ?

#45

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

No branches or pull requests

2 participants