refactor: remove conditional sqlite fallback and force postgresql database configuration
Some checks failed
Deploy Beta (NATIVE) / deploy (push) Failing after 19s
Some checks failed
Deploy Beta (NATIVE) / deploy (push) Failing after 19s
This commit is contained in:
parent
757cbc85ae
commit
a3be8f0e6d
1 changed files with 23 additions and 46 deletions
|
|
@ -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']
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue