Update config
This commit is contained in:
parent
bc31348313
commit
0e981fce87
33
config.py
33
config.py
@ -4,13 +4,26 @@ from dotenv import load_dotenv
|
||||
|
||||
load_dotenv(".env")
|
||||
|
||||
SECRET_KEY = environ.get("SECRET_KEY")
|
||||
DB_USER = environ.get("DB_USER")
|
||||
DB_PASSWORD = environ.get("DB_PASSWORD")
|
||||
DB_HOST = environ.get("DB_HOST")
|
||||
DB_PORT = environ.get("DB_PORT")
|
||||
DB_NAME = environ.get("DB_NAME")
|
||||
DB_SOCKET_DIR = environ.get("DB_SOCKET_DIR", "/cloudsql")
|
||||
CLOUD_SQL_CONNECTION_NAME = environ.get("CLOUD_SQL_CONNECTION_NAME")
|
||||
# DB_URL = f"postgres+psycopg2://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}?host={DB_SOCKET_DIR}/{CLOUD_SQL_CONNECTION_NAME}"
|
||||
DB_URL = f"postgres+psycopg2://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}"
|
||||
|
||||
class Config:
|
||||
SECRET_KEY = environ.get("SECRET_KEY")
|
||||
DB_USER = environ.get("DB_USER")
|
||||
DB_PASSWORD = environ.get("DB_PASSWORD")
|
||||
DB_HOST = environ.get("DB_HOST")
|
||||
DB_PORT = environ.get("DB_PORT")
|
||||
DB_NAME = environ.get("DB_NAME")
|
||||
|
||||
|
||||
class ProductionConfig(Config):
|
||||
FLASK_ENV = "production"
|
||||
DEBUG = False
|
||||
DB_SOCKET_DIR = environ.get("DB_SOCKET_DIR", "/cloudsql")
|
||||
CLOUD_SQL_CONNECTION_NAME = environ.get("CLOUD_SQL_CONNECTION_NAME")
|
||||
DB_URL = f"postgres+psycopg2://{Config.DB_USER}:{Config.DB_PASSWORD}@{Config.DB_HOST}:{Config.DB_PORT}/{Config.DB_NAME}?host={DB_SOCKET_DIR}/{CLOUD_SQL_CONNECTION_NAME}"
|
||||
|
||||
|
||||
class DevelopmentConfig(Config):
|
||||
FLASK_ENV = "development"
|
||||
DEBUG = True
|
||||
TESTING = True
|
||||
DB_URL = f"postgres+psycopg2://{Config.DB_USER}:{Config.DB_PASSWORD}@{Config.DB_HOST}:{Config.DB_PORT}/{Config.DB_NAME}"
|
||||
|
31
database.py
31
database.py
@ -1,12 +1,16 @@
|
||||
from flask import current_app, g
|
||||
import sqlalchemy
|
||||
from sqlalchemy import Column, JSON, String, Integer, create_engine, ForeignKey, func
|
||||
import os
|
||||
from sqlalchemy import Column, JSON, String, Integer, create_engine, ForeignKey, func, ARRAY
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.ext.associationproxy import association_proxy
|
||||
from sqlalchemy.orm import sessionmaker, relationship
|
||||
from config import DB_URL
|
||||
from werkzeug.utils import import_string
|
||||
|
||||
engine = create_engine(DB_URL)
|
||||
|
||||
environment_configuration = os.environ['CONFIGURATION_SETUP']
|
||||
config = import_string(environment_configuration)
|
||||
engine = create_engine(config.DB_URL)
|
||||
Session = sessionmaker(bind=engine)
|
||||
Base = declarative_base()
|
||||
|
||||
@ -19,6 +23,12 @@ class AllQuestions(Base):
|
||||
answer = Column(String)
|
||||
addresses = Column(String)
|
||||
|
||||
def __init__(self, question_id, question, answer, addresses):
|
||||
self.question_id = question_id
|
||||
self.question = question
|
||||
self.answer = answer
|
||||
self.addresses = addresses
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Question: {self.question_id}>"
|
||||
|
||||
@ -35,6 +45,12 @@ class HiddenAnswer(Base):
|
||||
answer = association_proxy("all_question_relationship", "answer")
|
||||
addresses = association_proxy("all_question_relationship", "addresses")
|
||||
|
||||
def __init__(self, question_id, difficulty, hint, base_question):
|
||||
self.question_id = question_id
|
||||
self.difficulty = difficulty
|
||||
self.hint = hint
|
||||
self.all_question_relationship = base_question
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Question Hidden Answer: {self.question_id}>"
|
||||
|
||||
@ -45,13 +61,20 @@ class MultipleChoice(Base):
|
||||
question_id = Column(Integer, ForeignKey("all_questions.question_id"), primary_key=True)
|
||||
difficulty = Column(Integer)
|
||||
hint = Column(JSON)
|
||||
wrong_answers = Column(String)
|
||||
wrong_answers = Column(ARRAY(String))
|
||||
|
||||
all_question_relationship = relationship("AllQuestions", primaryjoin="MultipleChoice.question_id==AllQuestions.question_id", lazy="joined", uselist=False)
|
||||
question = association_proxy("all_question_relationship", "question")
|
||||
answer = association_proxy("all_question_relationship", "answer")
|
||||
addresses = association_proxy("all_question_relationship", "addresses")
|
||||
|
||||
def __init__(self, question_id, difficulty, hint, wrong_answers, base_question):
|
||||
self.question_id = question_id
|
||||
self.difficulty = difficulty
|
||||
self.hint = hint
|
||||
self.wrong_answers = wrong_answers
|
||||
self.all_question_relationship = base_question
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Question Multiple Choice: {self.question_id}>"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user