diff --git a/config/settings.py b/config/settings.py index 5fbf5ae..8f17a30 100644 --- a/config/settings.py +++ b/config/settings.py @@ -87,56 +87,33 @@ WSGI_APPLICATION = 'config.wsgi.application' # --------------------------------------------------------------------------- # Database Configuration # --------------------------------------------------------------------------- -import socket -def is_postgres_available(): - try: - s = socket.create_connection(('127.0.0.1', 5432), timeout=1) - s.close() - return True - except OSError: - return False +import os -if is_postgres_available(): - db_credentials = { - 'ENGINE': 'django.db.backends.postgresql', - 'USER': os.environ.get('DB_USER', 'vignesh'), - 'PASSWORD': os.environ.get('DB_PASSWORD', 'vtechnosoft@123A'), - 'HOST': os.environ.get('DB_HOST', '127.0.0.1'), - 'PORT': os.environ.get('DB_PORT', '5432'), - } +db_credentials = { + 'ENGINE': 'django.db.backends.postgresql', + 'USER': os.environ.get('DB_USER', 'vignesh'), + 'PASSWORD': os.environ.get('DB_PASSWORD', 'vtechnosoft@123A'), + 'HOST': os.environ.get('DB_HOST', '127.0.0.1'), + 'PORT': os.environ.get('DB_PORT', '5432'), +} - env_name = os.environ.get('ENVIRONMENT', 'prod') - db_suffix = f'_{env_name}' +env_name = os.environ.get('ENVIRONMENT', 'prod') +db_suffix = f'_{env_name}' - DATABASES = { - 'default': { - 'NAME': f'sellerprofile{db_suffix}', - **db_credentials - }, - 'customerprofile': { - 'NAME': f'customerprofile{db_suffix}', - **db_credentials - }, - 'productprofile': { - 'NAME': f'productprofile{db_suffix}', - **db_credentials - } - } -else: - DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', - }, - 'customerprofile': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', - }, - 'productprofile': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', - } +DATABASES = { + 'default': { + 'NAME': f'sellerprofile{db_suffix}', + **db_credentials + }, + 'customerprofile': { + 'NAME': f'customerprofile{db_suffix}', + **db_credentials + }, + 'productprofile': { + 'NAME': f'productprofile{db_suffix}', + **db_credentials } +} DATABASE_ROUTERS = ['config.db_router.DatabaseRouter']