-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added populating db with seed data and cleanup
- Loading branch information
1 parent
1ef4368
commit e07c6b0
Showing
2 changed files
with
13 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,6 @@ then | |
fi | ||
|
||
python manage.py create_db | ||
python manage.py seed_db | ||
|
||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |