refactored table creation into seperate function
This commit is contained in:
parent
70b33b5c07
commit
efd76ee228
|
|
@ -2,3 +2,4 @@ data/
|
|||
*__pycache__
|
||||
*env
|
||||
*.code-workspace
|
||||
sandbox/
|
||||
16
src/db.py
16
src/db.py
|
|
@ -52,6 +52,14 @@ class RecipeIngredientParts(Base):
|
|||
ingredient = Column(String)
|
||||
supplement = Column(String)
|
||||
|
||||
class IngredientConnection(Base):
|
||||
__tablename__ = 'IngredientConnection'
|
||||
|
||||
ingredient_a = Column(String, primary_key = True)
|
||||
ingredient_b = Column(String, primary_key = True)
|
||||
recipe_count = Column(Integer)
|
||||
UniqueConstraint(ingredient_a, ingredient_b)
|
||||
|
||||
|
||||
|
||||
def get_engine(use_dotenv = True, **kargs):
|
||||
|
|
@ -70,7 +78,11 @@ def get_engine(use_dotenv = True, **kargs):
|
|||
return create_engine(eng_url)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
eng = get_engine()
|
||||
def create_tables(eng):
|
||||
logging.info(f"Createing DB Tables: {eng.url}")
|
||||
Base.metadata.create_all(eng, checkfirst=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
eng = get_engine()
|
||||
create_tables(eng)
|
||||
|
|
|
|||
Loading…
Reference in New Issue