dynamic database
This commit is contained in:
@@ -4,6 +4,8 @@ ENV PYTHONFAULTHANDLER=1
|
|||||||
|
|
||||||
ENV PYTHONUNBUFFERED=1
|
ENV PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
|
ENV MODE="DEVELOPMENT"
|
||||||
|
|
||||||
RUN mkdir -p /app
|
RUN mkdir -p /app
|
||||||
|
|
||||||
COPY requirements.txt /app
|
COPY requirements.txt /app
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ ENV PYTHONFAULTHANDLER=1
|
|||||||
|
|
||||||
ENV PYTHONUNBUFFERED=1
|
ENV PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
|
ENV MODE="PRODUCTION"
|
||||||
|
|
||||||
RUN mkdir -p /app
|
RUN mkdir -p /app
|
||||||
|
|
||||||
COPY requirements.txt /app
|
COPY requirements.txt /app
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from sqlalchemy import Column, Integer,\
|
from sqlalchemy import Column, Integer,\
|
||||||
DECIMAL, Text,\
|
DECIMAL, TEXT,\
|
||||||
VARCHAR, TIMESTAMP, Date, INTEGER
|
VARCHAR, TIMESTAMP, DATE, INTEGER
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime
|
||||||
from database import Base
|
from database import Base
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
20
config.py
Normal file
20
config.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
def load_config(mode=os.environ.get('MODE')):
|
||||||
|
|
||||||
|
try:
|
||||||
|
print(f"mode is {mode}")
|
||||||
|
if mode == 'PRODUCTION':
|
||||||
|
|
||||||
|
from settings_prod import ApplicationConfig
|
||||||
|
return ApplicationConfig
|
||||||
|
elif mode == 'DEVELOPMENT':
|
||||||
|
|
||||||
|
from settings_local import ApplicationConfig
|
||||||
|
return ApplicationConfig
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
except ImportError:
|
||||||
|
from settings_local import ApplicationConfig
|
||||||
|
return ApplicationConfig
|
||||||
15
database.py
15
database.py
@@ -2,14 +2,19 @@ from sqlalchemy import create_engine
|
|||||||
from sqlalchemy.engine import URL
|
from sqlalchemy.engine import URL
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
from sqlalchemy.orm import declarative_base
|
from sqlalchemy.orm import declarative_base
|
||||||
|
from config import load_config
|
||||||
|
|
||||||
|
|
||||||
|
ApplicationConfig = load_config()
|
||||||
|
|
||||||
|
|
||||||
url = URL.create(
|
url = URL.create(
|
||||||
drivername="postgresql",
|
drivername="postgresql",
|
||||||
username="postgres",
|
username=ApplicationConfig.POSTGRES_USERNAME,
|
||||||
password="password",
|
password=ApplicationConfig.POSTGRES_PW,
|
||||||
host="192.168.1.204",
|
host=ApplicationConfig.POSTGRES_SERVER,
|
||||||
database="eamco",
|
database=ApplicationConfig.POSTGRES_DBNAME00,
|
||||||
port=5432
|
port=ApplicationConfig.POSTGRES_PORT
|
||||||
)
|
)
|
||||||
|
|
||||||
engine = create_engine(url)
|
engine = create_engine(url)
|
||||||
|
|||||||
5
main.py
5
main.py
@@ -1,6 +1,11 @@
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from app.routers import delivery
|
from app.routers import delivery
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
from config import load_config
|
||||||
|
|
||||||
|
|
||||||
|
ApplicationConfig = load_config()
|
||||||
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|||||||
19
settings_local.py
Normal file
19
settings_local.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
|
||||||
|
class ApplicationConfig:
|
||||||
|
"""
|
||||||
|
Basic Configuration for a generic User
|
||||||
|
"""
|
||||||
|
CURRENT_SETTINGS = 'LOCAL'
|
||||||
|
# databases info
|
||||||
|
POSTGRES_USERNAME = 'postgres'
|
||||||
|
POSTGRES_PW = 'password'
|
||||||
|
POSTGRES_SERVER = '192.168.1.204'
|
||||||
|
POSTGRES_PORT = '5432'
|
||||||
|
POSTGRES_DBNAME00 = 'eamco'
|
||||||
|
SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(POSTGRES_USERNAME,
|
||||||
|
POSTGRES_PW,
|
||||||
|
POSTGRES_SERVER,
|
||||||
|
POSTGRES_DBNAME00
|
||||||
|
)
|
||||||
|
|
||||||
17
settings_prod.py
Normal file
17
settings_prod.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
class ApplicationConfig:
|
||||||
|
"""
|
||||||
|
Basic Configuration for a generic User
|
||||||
|
"""
|
||||||
|
CURRENT_SETTINGS = 'LOCAL'
|
||||||
|
# databases info
|
||||||
|
POSTGRES_USERNAME = 'postgres'
|
||||||
|
POSTGRES_PW = 'password'
|
||||||
|
POSTGRES_SERVER = '192.168.1.204'
|
||||||
|
POSTGRES_PORT = '5432'
|
||||||
|
POSTGRES_DBNAME00 = 'auburnoil'
|
||||||
|
SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(POSTGRES_USERNAME,
|
||||||
|
POSTGRES_PW,
|
||||||
|
POSTGRES_SERVER,
|
||||||
|
POSTGRES_DBNAME00
|
||||||
|
)
|
||||||
|
SQLALCHEMY_BINDS = {'eamco': SQLALCHEMY_DATABASE_URI}
|
||||||
Reference in New Issue
Block a user