2025-05-18 00:18:54 -05:00

36 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import click
from flask.cli import with_appcontext
from . import db
from .core.models import User
import os
@click.command('seed-admin')
@with_appcontext
def seed_admin():
"""Seeds only the default admin user unless SEED_EXTRA_DATA=true"""
admin_email = os.getenv('ADMIN_EMAIL', 'admin@example.com')
admin_password = os.getenv('ADMIN_PASSWORD', 'admin123')
if not User.query.filter_by(email=admin_email).first():
click.echo(f"[✔] Creating default admin: {admin_email}")
user = User(
email=admin_email,
password_hash=admin_password, # In production, hash this
role='admin',
is_verified=True
)
db.session.add(user)
db.session.commit()
else:
click.echo("[] Admin user already exists.")
if os.getenv("SEED_EXTRA_DATA", "false").lower() == "true":
click.echo("[] SEED_EXTRA_DATA=true, seeding additional demo content...")
seed_extra_data()
else:
click.echo("[✔] Admin-only seed complete. Skipping extras.")
def seed_extra_data():
# Placeholder for future extended seed logic
pass