Skip to content

Commit

Permalink
added populating db with seed data and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kcrane3576 committed Jun 12, 2022
1 parent 1ef4368 commit e07c6b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions services/web/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ then
fi

python manage.py create_db
python manage.py seed_db

exec "$@"
15 changes: 12 additions & 3 deletions services/web/manage.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
from flask.cli import FlaskGroup
from project import app, db
from project import app, db, User


# Enables the use of cli commands to be run alongside docker-compose
# eg: docker-compose exec web python manage.py create_db
# Triggered as part of the launch of the flask app so it is set up automatically in entrypoint.sh
cli = FlaskGroup(app)


# Enables the use of cli commands to be run alongside docker-compose
# eg: docker-compose exec web python manage.py create_db
# Reset db on start up to clean state
@cli.command("create_db")
def create_db():
db.drop_all()
db.create_all()
db.session.commit()


# Populate db with user(s)
@cli.command("seed_db")
def seed_db():
db.session.add(User(email="user@company.com"))
db.session.commit()


if __name__ == "__main__":
cli()

0 comments on commit e07c6b0

Please sign in to comment.