69 lines
1.5 KiB
Python
69 lines
1.5 KiB
Python
import typer
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import Session
|
|
|
|
from dengfun.retail.bootstrap import (
|
|
bootstrap_clients,
|
|
bootstrap_discounts,
|
|
bootstrap_items,
|
|
bootstrap_locations,
|
|
bootstrap_providers,
|
|
bootstrap_stock,
|
|
bootstrap_taskowners,
|
|
)
|
|
from dengfun.retail.models import Base
|
|
from dengfun.retail.sql.sync import funcandproc
|
|
|
|
app = typer.Typer()
|
|
|
|
|
|
@app.command()
|
|
def init(db_uri: str):
|
|
"""Persist the schema on the database
|
|
|
|
Args:
|
|
db_uri (str): SQLAlchemy db uri
|
|
"""
|
|
engine = create_engine(db_uri, echo=True)
|
|
Base.metadata.create_all(engine)
|
|
|
|
|
|
@app.command()
|
|
def sync(db_uri: str):
|
|
"""Sync the functions, procedures, triggers and views
|
|
|
|
Args:
|
|
db_uri (str): SQLAlchemy db uri
|
|
"""
|
|
funcandproc(db_uri)
|
|
|
|
|
|
@app.command()
|
|
def bootstrap(db_uri: str):
|
|
"""Populate the databse with data. Only execute on an empty database
|
|
|
|
Args:
|
|
db_uri (str): Sqlalchemy db uri
|
|
"""
|
|
engine = create_engine(db_uri)
|
|
|
|
with Session(engine) as session:
|
|
print("Discounts...")
|
|
bootstrap_discounts(session)
|
|
print("Providers...")
|
|
bootstrap_providers(session)
|
|
print("Locations...")
|
|
bootstrap_locations(session)
|
|
print("Items...")
|
|
bootstrap_items(session)
|
|
print("Clients...")
|
|
bootstrap_clients(session)
|
|
print("Stockage...")
|
|
bootstrap_stock(session)
|
|
print("TaskOwners")
|
|
bootstrap_taskowners(session)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app()
|