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

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
data/ data/
*__pycache__ *__pycache__
*env *env
*.code-workspace *.code-workspace
sandbox/

View File

@ -52,6 +52,14 @@ class RecipeIngredientParts(Base):
ingredient = Column(String) ingredient = Column(String)
supplement = 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): def get_engine(use_dotenv = True, **kargs):
@ -70,7 +78,11 @@ def get_engine(use_dotenv = True, **kargs):
return create_engine(eng_url) return create_engine(eng_url)
if __name__ == "__main__": def create_tables(eng):
eng = get_engine()
logging.info(f"Createing DB Tables: {eng.url}") logging.info(f"Createing DB Tables: {eng.url}")
Base.metadata.create_all(eng, checkfirst=True) Base.metadata.create_all(eng, checkfirst=True)
if __name__ == "__main__":
eng = get_engine()
create_tables(eng)