mirror of
https://github.com/inventree/InvenTree.git
synced 2025-11-13 11:26:42 +00:00
improve docker dx with empty migration set (#10774)
* if we are in docker and empty - init db * use structlog * remove logging change * reduce diff * ignore in test mode * add changes from review
This commit is contained in:
@@ -321,6 +321,18 @@ class InvenTreeConfig(AppConfig):
|
||||
return
|
||||
|
||||
if not InvenTree.tasks.check_for_migrations():
|
||||
# Detect if this an empty database - if so, start with a fresh migration
|
||||
if (
|
||||
settings.DOCKER
|
||||
and not InvenTree.ready.isInTestMode()
|
||||
and not InvenTree.ready.isRunningMigrations()
|
||||
and InvenTree.tasks.get_migration_count() == 0
|
||||
):
|
||||
logger.warning(
|
||||
'INVE-W8: Empty database detected - trying to run migrations'
|
||||
)
|
||||
InvenTree.tasks.check_for_migrations(force_run=True)
|
||||
else:
|
||||
logger.error('INVE-W8: Database Migrations required')
|
||||
sys.exit(1)
|
||||
MIGRATIONS_CHECK_DONE = True
|
||||
|
||||
@@ -661,6 +661,12 @@ def get_migration_plan():
|
||||
return plan
|
||||
|
||||
|
||||
def get_migration_count():
|
||||
"""Returns the number of all detected migrations."""
|
||||
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
|
||||
return executor.loader.applied_migrations
|
||||
|
||||
|
||||
@tracer.start_as_current_span('check_for_migrations')
|
||||
@scheduled_task(ScheduledTask.DAILY)
|
||||
def check_for_migrations(force: bool = False, reload_registry: bool = True) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user