From 2b97466ad6b5939356ebfd06268e5a07b2869ee5 Mon Sep 17 00:00:00 2001 From: jordan Date: Sat, 25 Jun 2011 15:13:15 +0000 Subject: [PATCH] Jira OSQA-712, migrating to the new Databases setting format git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1079 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/base.py | 15 +++++++++++++++ .../management/commands/create_extended_user.py | 7 +++++-- forum_modules/mysqlfulltext/__init__.py | 6 ++++-- forum_modules/pgfulltext/__init__.py | 7 ++++--- forum_modules/updater/base.py | 5 ++++- settings_local.py.dist | 16 ++++++++++------ 6 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 forum/base.py diff --git a/forum/base.py b/forum/base.py new file mode 100644 index 0000000..a045216 --- /dev/null +++ b/forum/base.py @@ -0,0 +1,15 @@ +from django.conf import settings as django_settings + +def get_database_engine(): + try: + database_type = django_settings.DATABASE_ENGINE + + if len(database_type) == 0: + raise Exception('Empty old style database engine') + except: + try: + database_type = django_settings.DATABASES['default']['ENGINE'] + except: + database_type = 'unknown' + + return str(database_type) \ No newline at end of file diff --git a/forum/management/commands/create_extended_user.py b/forum/management/commands/create_extended_user.py index c8a5ff1..768e18d 100644 --- a/forum/management/commands/create_extended_user.py +++ b/forum/management/commands/create_extended_user.py @@ -1,3 +1,6 @@ +from forum.base import get_database_engine + +database_type = get_database_engine() PG_MIGRATION_QUERY = """ SELECT id AS user_ptr_id, is_approved, email_isvalid, email_key, reputation, gravatar, gold, silver, bronze, questions_per_page, last_seen, real_name, website, location, date_of_birth, about, hide_ignored_questions, tag_filter_setting INTO forum_user FROM auth_user; @@ -270,10 +273,10 @@ from django.conf import settings class Command(NoArgsCommand): def handle_noargs(self, **options): - if settings.DATABASE_ENGINE in ('postgresql_psycopg2', 'postgresql', ): + if database_type.__contains__('postgresql'): migration_query = PG_MIGRATION_QUERY fkeys_query = PG_FKEYS_QUERY - elif settings.DATABASE_ENGINE == 'mysql': + elif database_type.__contains__('mysql'): migration_query = MYSQL_MIGRATION_QUERY fkeys_query = MYSQL_FKEYS_QUERY else: diff --git a/forum_modules/mysqlfulltext/__init__.py b/forum_modules/mysqlfulltext/__init__.py index 679d703..5591015 100644 --- a/forum_modules/mysqlfulltext/__init__.py +++ b/forum_modules/mysqlfulltext/__init__.py @@ -1,12 +1,14 @@ +from forum.base import get_database_engine +database_type = get_database_engine() + NAME = 'Mysql Full Text Search' DESCRIPTION = "Enables Mysql full text search functionality." try: import MySQLdb import settings_local - CAN_USE = settings_local.DATABASE_ENGINE in ('mysql', 'pooled_mysql') + CAN_USE = 'mysql' in database_type except Exception, e: import traceback traceback.print_exc() CAN_USE = False - \ No newline at end of file diff --git a/forum_modules/pgfulltext/__init__.py b/forum_modules/pgfulltext/__init__.py index 20cd355..05dcb3d 100644 --- a/forum_modules/pgfulltext/__init__.py +++ b/forum_modules/pgfulltext/__init__.py @@ -1,10 +1,11 @@ +from forum.base import get_database_engine +database_type = get_database_engine() + NAME = 'Postgresql Full Text Search' DESCRIPTION = "Enables PostgreSql full text search functionality." try: import psycopg2 - from django.conf import settings - CAN_USE = settings.DATABASE_ENGINE in ('postgresql_psycopg2', 'postgresql', ) + CAN_USE = 'postgresql' in database_type except: CAN_USE = False - \ No newline at end of file diff --git a/forum_modules/updater/base.py b/forum_modules/updater/base.py index 3ccf97d..c5bac16 100644 --- a/forum_modules/updater/base.py +++ b/forum_modules/updater/base.py @@ -13,6 +13,7 @@ import logging from xml.dom.minidom import parse, parseString +from forum.startup import get_database_engine from forum.models import Question, User from forum.settings import APP_URL, SVN_REVISION, APP_TITLE, APP_DESCRIPTION from django import VERSION as DJANGO_VERSION @@ -88,6 +89,8 @@ def check_for_updates(): admin_emails_xml += '' % email admin_emails_xml += '' + database_type = get_database_engine() + statistics = """ @@ -113,7 +116,7 @@ def check_for_updates(): 'active_users' : get_active_users(), 'python_version' : ''.join(sys.version.splitlines()), 'django_version' : str(DJANGO_VERSION), - 'database' : django_settings.DATABASE_ENGINE, + 'database' : database_type, 'os' : str(os.uname()), 'emails' : admin_emails_xml, } diff --git a/settings_local.py.dist b/settings_local.py.dist index afcc539..96468bc 100644 --- a/settings_local.py.dist +++ b/settings_local.py.dist @@ -24,12 +24,16 @@ TEMPLATE_DEBUG = DEBUG INTERNAL_IPS = ('127.0.0.1',) -DATABASE_NAME = '' # Or path to database file if using sqlite3. -DATABASE_USER = '' # Not used with sqlite3. -DATABASE_PASSWORD = '' # Not used with sqlite3. -DATABASE_ENGINE = '' #mysql, etc -DATABASE_HOST = '' -DATABASE_PORT = '' +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'osqa', + 'USER': 'root', + 'PASSWORD': '', + 'HOST': '', + 'PORT': '', + } +} CACHE_BACKEND = 'file://%s' % os.path.join(os.path.dirname(__file__),'cache').replace('\\','/') #CACHE_BACKEND = 'dummy://' -- 2.39.5