Files
natureinpots_community/plugins/cli/seed.py
2025-05-24 03:23:15 -05:00

33 lines
995 B
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 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.")