From d09fb5a3490ef7cf9eb957bd3ca7f87386203f02 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 19 Oct 2010 19:44:41 +0200 Subject: [PATCH] settings: Prompt for a database login when using South migrations. This allows the normal database user to be unprivileged, while performing schema migrations using a privileged user. --- settings.py | 4 ++++ southsettings.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 southsettings.py diff --git a/settings.py b/settings.py index f07aa72..54df1e2 100644 --- a/settings.py +++ b/settings.py @@ -17,6 +17,10 @@ MANAGERS = ADMINS # Import database settings from a default file (so we can keep those out # of git). from dbsettings import * +# Import alternative database settings for when running a south schema +# migration. The soutsettings.py takes care of detecting this case and +# prompting for a password, then. +from southsettings import * # Local time zone for this installation. Choices can be found here: # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name diff --git a/southsettings.py b/southsettings.py new file mode 100644 index 0000000..63ff314 --- /dev/null +++ b/southsettings.py @@ -0,0 +1,17 @@ +# Database settings for when doing a database migration using south, +# which requires more privileges. + +import sys +if 'manage.py' in sys.argv[0] and sys.argv[1] == 'migrate': + import south + + try: + # We cache the prompted values in the south module, since the + # settings module gets loaded multiple times... + DATABASE_USER = south.cached_db_user + DATABASE_PASSWORD = south.cached_db_pw + except AttributeError: + DATABASE_USER = raw_input("Privileged database user: ") + DATABASE_PASSWORD = raw_input("Database password for %s: " % DATABASE_USER) + south.cached_db_user = DATABASE_USER + south.cached_db_pw = DATABASE_PASSWORD -- 2.30.2