mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-16 01:36:29 +00:00
Auto migrating (#3741)
* base structure for updates * add base structure * add settingscheck * update docstring * only load plugins if needed * fix misstyping * run migration * check if there are open migrations * log open migration * add more logging * patch in fore reloading on unload * only run if database is ready * check every 5 minutes * remove non implemented feautres from desc * add command flag to makr if cmmand runs as worker * Add tests for migrations * factor mmigration plan into own function * Add print statements * add initial migrations for tests * remove last assertation * cleanup migrations after run * add flag to accept empty source code files * the flag is enough for reporting * fix test * do not run migrations on sqlite3 * make sure migrations don't fail if no plan ran * increase coverage for migration * spell fix * check for migrations daily * add a migration check after plugins are installed
This commit is contained in:
@@ -162,8 +162,12 @@ class PluginsRegistry:
|
||||
|
||||
logger.info('Finished loading plugins')
|
||||
|
||||
def unload_plugins(self):
|
||||
"""Unload and deactivate all IntegrationPlugins."""
|
||||
def unload_plugins(self, force_reload: bool = False):
|
||||
"""Unload and deactivate all IntegrationPlugins.
|
||||
|
||||
Args:
|
||||
force_reload (bool, optional): Also reload base apps. Defaults to False.
|
||||
"""
|
||||
|
||||
logger.info('Start unloading plugins')
|
||||
|
||||
@@ -176,7 +180,7 @@ class PluginsRegistry:
|
||||
self._clean_registry()
|
||||
|
||||
# deactivate all integrations
|
||||
self._deactivate_plugins()
|
||||
self._deactivate_plugins(force_reload=force_reload)
|
||||
|
||||
# remove maintenance
|
||||
if not _maintenance:
|
||||
@@ -184,11 +188,12 @@ class PluginsRegistry:
|
||||
|
||||
logger.info('Finished unloading plugins')
|
||||
|
||||
def reload_plugins(self, full_reload: bool = False):
|
||||
def reload_plugins(self, full_reload: bool = False, force_reload: bool = False):
|
||||
"""Safely reload.
|
||||
|
||||
Args:
|
||||
full_reload (bool, optional): Reload everything - including plugin mechanism. Defaults to False.
|
||||
force_reload (bool, optional): Also reload base apps. Defaults to False.
|
||||
"""
|
||||
# Do not reload whe currently loading
|
||||
if self.is_loading:
|
||||
@@ -197,8 +202,8 @@ class PluginsRegistry:
|
||||
logger.info('Start reloading plugins')
|
||||
|
||||
with maintenance_mode_on():
|
||||
self.unload_plugins()
|
||||
self.load_plugins(full_reload)
|
||||
self.unload_plugins(force_reload=force_reload)
|
||||
self.load_plugins(full_reload=full_reload)
|
||||
|
||||
logger.info('Finished reloading plugins')
|
||||
|
||||
@@ -470,9 +475,13 @@ class PluginsRegistry:
|
||||
self.activate_plugin_app(plugins, force_reload=force_reload, full_reload=full_reload)
|
||||
self.activate_plugin_url(plugins, force_reload=force_reload, full_reload=full_reload)
|
||||
|
||||
def _deactivate_plugins(self):
|
||||
"""Run deactivation functions for all plugins."""
|
||||
self.deactivate_plugin_app()
|
||||
def _deactivate_plugins(self, force_reload: bool = False):
|
||||
"""Run deactivation functions for all plugins.
|
||||
|
||||
Args:
|
||||
force_reload (bool, optional): Also reload base apps. Defaults to False.
|
||||
"""
|
||||
self.deactivate_plugin_app(force_reload=force_reload)
|
||||
self.deactivate_plugin_schedule()
|
||||
self.deactivate_plugin_settings()
|
||||
# endregion
|
||||
@@ -655,8 +664,12 @@ class PluginsRegistry:
|
||||
plugin_path = plugin.__module__.split('.')[0]
|
||||
return plugin_path
|
||||
|
||||
def deactivate_plugin_app(self):
|
||||
"""Deactivate AppMixin plugins - some magic required."""
|
||||
def deactivate_plugin_app(self, force_reload: bool = False):
|
||||
"""Deactivate AppMixin plugins - some magic required.
|
||||
|
||||
Args:
|
||||
force_reload (bool, optional): Also reload base apps. Defaults to False.
|
||||
"""
|
||||
# unregister models from admin
|
||||
for plugin_path in self.installed_apps:
|
||||
models = [] # the modelrefs need to be collected as poping an item in a iter is not welcomed
|
||||
@@ -693,7 +706,7 @@ class PluginsRegistry:
|
||||
|
||||
# reset load flag and reload apps
|
||||
settings.INTEGRATION_APPS_LOADED = False
|
||||
self._reload_apps()
|
||||
self._reload_apps(force_reload=force_reload)
|
||||
|
||||
# update urls to remove the apps from the site admin
|
||||
self._update_urls()
|
||||
|
Reference in New Issue
Block a user