seed roles in seed_db

This commit is contained in:
deflax 2024-04-01 20:00:56 +03:00
parent 2aca3bee15
commit c35f622d24

View file

@ -4,9 +4,9 @@ import os
from flask.cli import FlaskGroup from flask.cli import FlaskGroup
from app import app, db from app import app, db
from models import User from models import Role, User
from flask_migrate import Migrate from flask_migrate import Migrate, upgrade
cli = FlaskGroup(app) cli = FlaskGroup(app)
@ -19,25 +19,15 @@ def create_db():
db.create_all() db.create_all()
db.session.commit() db.session.commit()
@cli.command("seed_db") @cli.command("seed_db")
def seed_db(): def seed_db():
db.session.add(User(email="daniel@deflax.net"))
db.session.commit()
@cli.command("upgrade_db")
def upgrade_db():
"""Run deployment tasks."""
from flask_migrate import upgrade
from app.models import Role, User
# migrate database to latest revision
upgrade()
# create user roles # create user roles
Role.insert_roles() Role.insert_roles()
@cli.command("upgrade_db")
def upgrade_db():
# migrate database to latest revision
upgrade()
@cli.command("restore_db") @cli.command("restore_db")
def restore_db(restore_file): def restore_db(restore_file):