Deploy Development / deploy (push) Failing after 40s
Testdaten entstehen nur dort und werden danach entfernt, damit Dev und Produktion sie nicht behalten. Co-authored-by: Cursor <cursoragent@cursor.com>
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
"""Operator commands: migrate and create an account. Demo seed stays in the test suite."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
|
|
from app.auth.accounts import create_account
|
|
from app.core.settings import get_settings
|
|
from app.db.migrate import migrate
|
|
|
|
import psycopg
|
|
from psycopg.rows import dict_row
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser(prog="tsumugu")
|
|
sub = parser.add_subparsers(dest="command", required=True)
|
|
sub.add_parser("migrate")
|
|
sub.add_parser("seed-demo")
|
|
create = sub.add_parser("create-account")
|
|
create.add_argument("--email", required=True)
|
|
create.add_argument("--name", required=True)
|
|
create.add_argument("--password", required=True)
|
|
args = parser.parse_args()
|
|
settings = get_settings()
|
|
if args.command == "migrate":
|
|
applied = migrate(settings)
|
|
print("applied" if applied else "up to date")
|
|
return
|
|
if args.command == "seed-demo":
|
|
raise SystemExit("Testdaten legt nur die Test-Suite an und entfernt sie wieder.")
|
|
if len(args.password) < 10:
|
|
raise SystemExit("password must be at least 10 characters")
|
|
with psycopg.connect(settings.dsn(), row_factory=dict_row) as conn:
|
|
has_admin = conn.execute("SELECT 1 FROM auth_accounts WHERE is_superadmin LIMIT 1").fetchone()
|
|
account = create_account(conn, args.email, args.name, args.password, is_superadmin=has_admin is None)
|
|
conn.commit()
|
|
print(account["id"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|