refactored table creation into seperate function

This commit is contained in:
Andrei Stoica 2022-08-03 17:02:49 -04:00
parent 70b33b5c07
commit efd76ee228
2 changed files with 16 additions and 3 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ data/
*__pycache__
*env
*.code-workspace
sandbox/

View File

@ -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)