36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
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
|