API - remove init-data
step since no additional data is now required
+ remove config init from removed env. variables
This commit is contained in:
parent
e751fec1d0
commit
1a53d4a991
@ -93,7 +93,6 @@ firefox:
|
||||
- poetry config virtualenvs.create false
|
||||
- poetry install --no-interaction --quiet
|
||||
- flask db upgrade --directory fittrackee/migrations
|
||||
- flask init-data
|
||||
- setsid nohup flask run --with-threads -h 0.0.0.0 -p 5000 >> nohup.out 2>&1 &
|
||||
- export TEST_APP_URL=http://$(hostname --ip-address):5000
|
||||
- sleep 5
|
||||
|
5
Makefile
5
Makefile
@ -85,15 +85,10 @@ html:
|
||||
install-db:
|
||||
psql -U postgres -f db/create.sql
|
||||
$(FLASK) db upgrade --directory $(MIGRATIONS)
|
||||
$(FLASK) init-data
|
||||
|
||||
init-app-config:
|
||||
$(FLASK) init-app-config
|
||||
|
||||
init-db:
|
||||
$(FLASK) drop-db
|
||||
$(FLASK) db upgrade --directory $(MIGRATIONS)
|
||||
$(FLASK) init-data
|
||||
|
||||
install: install-client install-python
|
||||
|
||||
|
@ -6,4 +6,3 @@ source .env.docker
|
||||
|
||||
flask drop-db
|
||||
flask db upgrade --directory fittrackee/migrations
|
||||
flask init-data
|
@ -51,16 +51,16 @@ def create_app() -> Flask:
|
||||
email_service.init_email(app)
|
||||
|
||||
# get configuration from database
|
||||
from .application.models import AppConfig
|
||||
from .application.utils import init_config, update_app_config_from_database
|
||||
from .application.utils import (
|
||||
get_or_init_config,
|
||||
update_app_config_from_database,
|
||||
)
|
||||
|
||||
with app.app_context():
|
||||
# Note: check if "app_config" table exist to avoid errors when
|
||||
# dropping tables on dev environments
|
||||
if db.engine.dialect.has_table(db.engine.connect(), 'app_config'):
|
||||
db_app_config = AppConfig.query.one_or_none()
|
||||
if not db_app_config:
|
||||
_, db_app_config = init_config()
|
||||
db_app_config = get_or_init_config()
|
||||
update_app_config_from_database(app, db_app_config)
|
||||
|
||||
from .application.app_config import config_blueprint # noqa
|
||||
|
@ -11,8 +11,6 @@ from flask_migrate import upgrade
|
||||
from tqdm import tqdm
|
||||
|
||||
from fittrackee import create_app, db
|
||||
from fittrackee.application.utils import init_config
|
||||
from fittrackee.database_utils import init_database
|
||||
from fittrackee.workouts.models import Workout
|
||||
from fittrackee.workouts.utils import update_workout
|
||||
|
||||
@ -61,12 +59,6 @@ def drop_db() -> None:
|
||||
print('Uploaded files deleted.')
|
||||
|
||||
|
||||
@app.cli.command('init-data')
|
||||
def init_data() -> None:
|
||||
"""Init the database and application config."""
|
||||
init_database(app)
|
||||
|
||||
|
||||
@app.cli.command()
|
||||
def recalculate() -> None:
|
||||
print("Starting workouts data refresh")
|
||||
@ -85,20 +77,6 @@ def recalculate() -> None:
|
||||
db.session.commit()
|
||||
|
||||
|
||||
@app.cli.command('init-app-config')
|
||||
def init_app_config() -> None:
|
||||
"""Init application configuration."""
|
||||
print("Init application configuration")
|
||||
config_created, _ = init_config()
|
||||
if config_created:
|
||||
print("Creation done!")
|
||||
else:
|
||||
print(
|
||||
"Application configuration already existing in database. "
|
||||
"Please use web application to update it."
|
||||
)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
options = {'bind': f'{HOST}:{PORT}', 'workers': WORKERS}
|
||||
StandaloneApplication(app, options).run()
|
||||
|
@ -1,42 +1,28 @@
|
||||
import os
|
||||
from typing import Dict, List, Tuple
|
||||
from typing import Dict, List
|
||||
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee import db
|
||||
from fittrackee.users.models import User
|
||||
|
||||
from .models import AppConfig
|
||||
|
||||
MAX_FILE_SIZE = 1 * 1024 * 1024 # 1MB
|
||||
|
||||
|
||||
def init_config() -> Tuple[bool, AppConfig]:
|
||||
def get_or_init_config() -> AppConfig:
|
||||
"""
|
||||
init application configuration if not existing in database
|
||||
|
||||
Note: get some configuration values from env variables
|
||||
(for FitTrackee versions prior to v0.3.0)
|
||||
Init application configuration.
|
||||
"""
|
||||
existing_config = AppConfig.query.one_or_none()
|
||||
nb_users = User.query.count()
|
||||
if not existing_config:
|
||||
if existing_config:
|
||||
return existing_config
|
||||
config = AppConfig()
|
||||
config.max_users = (
|
||||
nb_users
|
||||
if os.getenv('REACT_APP_ALLOW_REGISTRATION') == "false"
|
||||
else 0
|
||||
)
|
||||
config.max_single_file_size = os.environ.get(
|
||||
'REACT_APP_MAX_SINGLE_FILE_SIZE', MAX_FILE_SIZE
|
||||
)
|
||||
config.max_zip_file_size = os.environ.get(
|
||||
'REACT_APP_MAX_ZIP_FILE_SIZE', MAX_FILE_SIZE * 10
|
||||
)
|
||||
config.max_users = 0 # no limitation
|
||||
config.max_single_file_size = MAX_FILE_SIZE
|
||||
config.max_zip_file_size = MAX_FILE_SIZE * 10
|
||||
db.session.add(config)
|
||||
db.session.commit()
|
||||
return True, config
|
||||
return False, existing_config
|
||||
return config
|
||||
|
||||
|
||||
def update_app_config_from_database(
|
||||
|
@ -1,14 +0,0 @@
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee.application.utils import (
|
||||
init_config,
|
||||
update_app_config_from_database,
|
||||
)
|
||||
|
||||
|
||||
def init_database(app: Flask) -> None:
|
||||
"""Init the database."""
|
||||
_, db_app_config = init_config()
|
||||
update_app_config_from_database(app, db_app_config)
|
||||
|
||||
print('Initial data stored in database.')
|
48
fittrackee/tests/application/test_database_utils.py
Normal file
48
fittrackee/tests/application/test_database_utils.py
Normal file
@ -0,0 +1,48 @@
|
||||
from flask import Flask
|
||||
|
||||
from fittrackee.application.models import AppConfig
|
||||
from fittrackee.application.utils import get_or_init_config
|
||||
|
||||
|
||||
class TestGetOrInitAppConfig:
|
||||
def test_it_creates_app_config(self, app_no_config: Flask) -> None:
|
||||
get_or_init_config()
|
||||
|
||||
assert AppConfig.query.count() == 1
|
||||
|
||||
def test_it_inits_max_users_with_default_value(
|
||||
self, app_no_config: Flask
|
||||
) -> None:
|
||||
get_or_init_config()
|
||||
|
||||
app_config = AppConfig.query.first()
|
||||
assert app_config.max_users == 0
|
||||
|
||||
def test_it_inits_max_single_file_size_with_default_value(
|
||||
self, app_no_config: Flask
|
||||
) -> None:
|
||||
get_or_init_config()
|
||||
|
||||
app_config = AppConfig.query.first()
|
||||
assert app_config.max_single_file_size == 1048576 # 1MB
|
||||
|
||||
def test_it_inits_max_zip_file_size_with_default_value(
|
||||
self, app_no_config: Flask
|
||||
) -> None:
|
||||
get_or_init_config()
|
||||
|
||||
app_config = AppConfig.query.first()
|
||||
assert app_config.max_zip_file_size == 10485760 # 10MB
|
||||
|
||||
def test_it_inits_gpx_limit_import_with_default_value(
|
||||
self, app_no_config: Flask
|
||||
) -> None:
|
||||
get_or_init_config()
|
||||
|
||||
app_config = AppConfig.query.first()
|
||||
assert app_config.gpx_limit_import == 10
|
||||
|
||||
def test_it_returns_existing_config(self, app: Flask) -> None:
|
||||
app_config = get_or_init_config()
|
||||
|
||||
assert app_config.max_users == 100
|
@ -63,7 +63,6 @@ Sphinx = "^4.4.0"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
fittrackee = 'fittrackee.__main__:main'
|
||||
fittrackee_init_data = 'fittrackee.__main__:init_data'
|
||||
fittrackee_upgrade_db = 'fittrackee.__main__:upgrade_db'
|
||||
fittrackee_worker = 'fittrackee.__main__:dramatiq_worker'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user