39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
|
|
from app.db.bootstrap import bootstrap_dev_data
|
|
from app.db.migrations import migrate_database
|
|
from app.db.session import SessionLocal
|
|
from app.settings import settings
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser(description="Initialize the MultiMailer database")
|
|
parser.add_argument("--with-dev-data", action="store_true", help="Create default tenant/user/roles and a development API key")
|
|
parser.add_argument("--dev-api-key", default=settings.dev_bootstrap_api_key, help="Development API key secret to create")
|
|
args = parser.parse_args()
|
|
|
|
migration = migrate_database()
|
|
if migration.reconciled_revision:
|
|
print(
|
|
"Reconciled legacy database marker "
|
|
f"to {migration.reconciled_revision}."
|
|
)
|
|
print(f"Database schema upgraded to {migration.current_revision}.")
|
|
|
|
if args.with_dev_data:
|
|
with SessionLocal() as session:
|
|
result = bootstrap_dev_data(session, api_key_secret=args.dev_api_key)
|
|
print(f"Tenant: {result.tenant.slug} ({result.tenant.id})")
|
|
print(f"User: {result.user.email} ({result.user.id})")
|
|
if result.created_api_key:
|
|
print("Development API key created:")
|
|
print(result.created_api_key.secret)
|
|
else:
|
|
print("Development API key already exists or was not requested.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|