initial commit after split
This commit is contained in:
1
src/govoplan_core/commands/__init__.py
Normal file
1
src/govoplan_core/commands/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from __future__ import annotations
|
||||
36
src/govoplan_core/commands/init_db.py
Normal file
36
src/govoplan_core/commands/init_db.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
|
||||
from govoplan_core.db.bootstrap import bootstrap_dev_data
|
||||
from govoplan_core.db.migrations import migrate_database
|
||||
from govoplan_core.db.session import configure_database, get_database
|
||||
from govoplan_core.settings import settings
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description="Initialize the GovOPlaN 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()
|
||||
|
||||
configure_database(settings.database_url)
|
||||
migration = migrate_database()
|
||||
if migration.reconciled_revision:
|
||||
print(f"Reconciled legacy database marker to {migration.reconciled_revision}.")
|
||||
print(f"Database schema upgraded to {migration.current_revision}.")
|
||||
|
||||
if args.with_dev_data:
|
||||
with get_database().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()
|
||||
Reference in New Issue
Block a user