2021-01-20 16:47:00 +01:00
|
|
|
from flask import Flask
|
|
|
|
|
2020-09-16 18:58:11 +02:00
|
|
|
from fittrackee import db
|
|
|
|
from fittrackee.application.utils import (
|
|
|
|
init_config,
|
|
|
|
update_app_config_from_database,
|
|
|
|
)
|
|
|
|
from fittrackee.users.models import User
|
2021-01-10 11:16:43 +01:00
|
|
|
from fittrackee.workouts.models import Sport
|
2020-09-16 18:58:11 +02:00
|
|
|
|
|
|
|
|
2021-01-02 19:28:03 +01:00
|
|
|
def init_database(app: Flask) -> None:
|
2020-09-16 18:58:11 +02:00
|
|
|
"""Init the database."""
|
|
|
|
admin = User(
|
|
|
|
username='admin', email='admin@example.com', password='mpwoadmin'
|
|
|
|
)
|
|
|
|
admin.admin = True
|
|
|
|
admin.timezone = 'Europe/Paris'
|
|
|
|
db.session.add(admin)
|
|
|
|
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)
|
2021-08-20 07:33:55 +02:00
|
|
|
sport = Sport(label='Mountain Biking (Electric)')
|
|
|
|
sport.img = '/img/sports/electric-mountain-biking.png'
|
|
|
|
sport.is_default = True
|
|
|
|
db.session.add(sport)
|
2020-09-16 18:58:11 +02:00
|
|
|
sport = Sport(label='Running')
|
|
|
|
sport.img = '/img/sports/running.png'
|
|
|
|
sport.is_default = True
|
|
|
|
db.session.add(sport)
|
2021-08-20 07:33:55 +02:00
|
|
|
sport = Sport(label='Trail')
|
|
|
|
sport.img = '/img/sports/trail.png'
|
|
|
|
sport.is_default = True
|
2021-09-01 11:19:11 +02:00
|
|
|
db.session.add(sport)
|
2020-09-16 18:58:11 +02:00
|
|
|
sport = Sport(label='Walking')
|
|
|
|
sport.img = '/img/sports/walking.png'
|
|
|
|
sport.is_default = True
|
|
|
|
db.session.add(sport)
|
2021-08-20 07:33:55 +02:00
|
|
|
sport = Sport(label='Skiing (Alpine)')
|
|
|
|
sport.img = '/img/sports/alpine-skiing.png'
|
|
|
|
sport.is_default = True
|
|
|
|
db.session.add(sport)
|
|
|
|
sport = Sport(label='Skiing (Cross Country)')
|
|
|
|
sport.img = '/img/sports/cross-country-skiing.png'
|
|
|
|
sport.is_default = True
|
2021-09-01 11:19:11 +02:00
|
|
|
db.session.add(sport)
|
2021-08-20 07:33:55 +02:00
|
|
|
sport = Sport(label='Rowing')
|
|
|
|
sport.img = '/img/sports/rowing.png'
|
|
|
|
sport.is_default = True
|
|
|
|
db.session.add(sport)
|
2020-09-16 18:58:11 +02:00
|
|
|
db.session.commit()
|
|
|
|
_, db_app_config = init_config()
|
|
|
|
update_app_config_from_database(app, db_app_config)
|
|
|
|
|
|
|
|
print('Initial data stored in database.')
|