fooder-api/fooder/__main__.py

34 lines
1,022 B
Python
Raw Normal View History

2023-04-01 16:19:12 +02:00
from argparse import ArgumentParser
if __name__ == "__main__":
parser = ArgumentParser()
group = parser.add_mutually_exclusive_group()
group.add_argument("--create-tables", action="store_true")
group.add_argument("--create-user", action="store_true")
parser.add_argument("--username", type=str, action="store")
parser.add_argument("--password", type=str, action="store")
args = parser.parse_args()
import sqlalchemy
from sqlalchemy.orm import Session
from .domain import Base
from .settings import Settings
settings = Settings()
engine = sqlalchemy.create_engine(settings.DB_URI.replace("+asyncpg", ""))
if args.create_tables:
Base.metadata.create_all(engine)
if args.create_user:
with Session(engine) as session:
from .domain.user import User
user = User(
username=args.username,
)
user.set_password(args.password)
session.add(user)
session.commit()