2018-05-11 17:55:46 +02:00
|
|
|
import shutil
|
|
|
|
|
2018-04-09 22:09:58 +02:00
|
|
|
from mpwo_api import create_app, db
|
2018-01-21 19:45:13 +01:00
|
|
|
from mpwo_api.activities.models import Sport
|
2017-12-16 21:00:46 +01:00
|
|
|
from mpwo_api.users.models import User
|
|
|
|
|
2018-04-09 22:09:58 +02:00
|
|
|
app = create_app()
|
|
|
|
|
2017-12-16 21:00:46 +01:00
|
|
|
|
|
|
|
@app.cli.command()
|
2018-01-20 19:12:34 +01:00
|
|
|
def drop_db():
|
2018-05-10 11:36:08 +02:00
|
|
|
"""Empty database for dev environments."""
|
|
|
|
db.engine.execute("DROP TABLE IF EXISTS alembic_version;")
|
2017-12-16 21:00:46 +01:00
|
|
|
db.drop_all()
|
2018-01-20 19:12:34 +01:00
|
|
|
db.session.commit()
|
|
|
|
print('Database dropped.')
|
2018-05-11 17:55:46 +02:00
|
|
|
shutil.rmtree(app.config['UPLOAD_FOLDER'], ignore_errors=True)
|
|
|
|
print('Uploaded files deleted.')
|
2018-01-20 19:12:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
@app.cli.command()
|
|
|
|
def init_data():
|
|
|
|
"""Init the database."""
|
2018-01-01 16:59:46 +01:00
|
|
|
admin = User(
|
|
|
|
username='admin',
|
|
|
|
email='admin@example.com',
|
|
|
|
password='mpwoadmin')
|
2017-12-17 09:16:08 +01:00
|
|
|
admin.admin = True
|
|
|
|
db.session.add(admin)
|
2018-05-16 23:52:55 +02:00
|
|
|
sport = Sport(label='Cycling (Sport)')
|
|
|
|
sport.img = '/img/sports/cycling-sport.png'
|
|
|
|
sport.is_default = True
|
|
|
|
db.session.add(sport)
|
|
|
|
sport = Sport(label='Cycling (Transport)')
|
|
|
|
sport.img = '/img/sports/cycling-transport.png'
|
|
|
|
sport.is_default = True
|
|
|
|
db.session.add(sport)
|
|
|
|
sport = Sport(label='Hiking')
|
|
|
|
sport.img = '/img/sports/hiking.png'
|
|
|
|
sport.is_default = True
|
|
|
|
db.session.add(sport)
|
|
|
|
sport = Sport(label='Mountain Biking')
|
|
|
|
sport.img = '/img/sports/mountain-biking.png'
|
|
|
|
sport.is_default = True
|
|
|
|
db.session.add(sport)
|
|
|
|
sport = Sport(label='Running')
|
|
|
|
sport.img = '/img/sports/running.png'
|
|
|
|
sport.is_default = True
|
|
|
|
db.session.add(sport)
|
|
|
|
sport = Sport(label='Walking')
|
|
|
|
sport.img = '/img/sports/walking.png'
|
|
|
|
sport.is_default = True
|
|
|
|
db.session.add(sport)
|
2017-12-16 21:00:46 +01:00
|
|
|
db.session.commit()
|
2018-01-21 19:45:13 +01:00
|
|
|
print('Initial data stored in database.')
|
2017-12-16 21:00:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run()
|