refactored table creation into seperate function
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
data/
|
||||
*__pycache__
|
||||
*env
|
||||
*.code-workspace
|
||||
*.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)
|
||||
|
||||
Reference in New Issue
Block a user