33 lines
995 B
Python
33 lines
995 B
Python
import click
|
||
from flask.cli import with_appcontext
|
||
from plugins.plant.models import Plant
|
||
from plugins.auth.models import User
|
||
from app import db
|
||
|
||
|
||
@click.command('preload-data')
|
||
@with_appcontext
|
||
def preload_data():
|
||
click.echo("Preloading data...")
|
||
if not Plant.query.first():
|
||
plant = Plant(name="Default Plant")
|
||
db.session.add(plant)
|
||
db.session.commit()
|
||
click.echo("Default plant added.")
|
||
else:
|
||
click.echo("Plant data already exists.")
|
||
|
||
|
||
@click.command('seed-admin')
|
||
@with_appcontext
|
||
def seed_admin():
|
||
click.echo("Seeding admin user...")
|
||
if not User.query.filter_by(email='admin@example.com').first():
|
||
user = User(email='admin@example.com', role='admin', is_verified=True)
|
||
user.set_password('password') # Make sure this method exists in your model
|
||
db.session.add(user)
|
||
db.session.commit()
|
||
click.echo("✅ Admin user created.")
|
||
else:
|
||
click.echo("ℹ️ Admin user already exists.")
|