feature/migrations, closes #19 #20
|
@ -3,7 +3,6 @@ from click.decorators import pass_context
|
|||
from flask.cli import with_appcontext
|
||||
from flask_migrate import upgrade
|
||||
|
||||
from flaschengeist.alembic import alembic_migrations_path
|
||||
from flaschengeist.controller import pluginController
|
||||
from flaschengeist.utils.hook import Hook
|
||||
|
||||
|
@ -16,7 +15,7 @@ def install(ctx: click.Context):
|
|||
plugins = pluginController.get_enabled_plugins()
|
||||
|
||||
# Install database
|
||||
upgrade(alembic_migrations_path, revision="heads")
|
||||
upgrade(revision="flaschengeist@head")
|
||||
|
||||
# Install plugins
|
||||
for plugin in plugins:
|
||||
|
|
|
@ -7,6 +7,7 @@ from typing import Union
|
|||
from flask import current_app
|
||||
from werkzeug.exceptions import NotFound, BadRequest
|
||||
from sqlalchemy.exc import OperationalError
|
||||
from flask_migrate import upgrade as database_upgrade
|
||||
from importlib.metadata import entry_points
|
||||
|
||||
from flaschengeist import version as flaschengeist_version
|
||||
|
@ -83,14 +84,19 @@ def install_plugin(plugin_name: str):
|
|||
raise NotFound
|
||||
|
||||
cls = entry_point[0].load()
|
||||
plugin = cls.query.filter(Plugin.name == plugin_name).one_or_none()
|
||||
plugin: Plugin = cls.query.filter(Plugin.name == plugin_name).one_or_none()
|
||||
if plugin is None:
|
||||
plugin = cls(name=plugin_name, installed_version=entry_point[0].dist.version)
|
||||
db.session.add(plugin)
|
||||
db.session.flush()
|
||||
db.session.commit()
|
||||
# Custom installation steps
|
||||
plugin.install()
|
||||
db.session.commit()
|
||||
# Check migrations
|
||||
directory = entry_point[0].dist.locate_file("")
|
||||
for loc in entry_point[0].module.split(".") + ["migrations"]:
|
||||
directory /= loc
|
||||
if directory.exists():
|
||||
database_upgrade(revision=f"{plugin_name}@head")
|
||||
|
||||
return plugin
|
||||
|
||||
|
|
|
@ -39,11 +39,7 @@ def configure_alembic(config: Config):
|
|||
migrations = [config.get_main_option("script_location") + "/migrations"]
|
||||
|
||||
# Gather all migration paths
|
||||
all_plugins = entry_points(group="flaschengeist.plugins")
|
||||
for plugin in pluginController.get_enabled_plugins():
|
||||
entry_point = all_plugins.select(name=plugin.name)
|
||||
if not entry_point:
|
||||
continue
|
||||
for entry_point in entry_points(group="flaschengeist.plugins"):
|
||||
try:
|
||||
directory = entry_point.dist.locate_file("")
|
||||
for loc in entry_point.module.split(".") + ["migrations"]:
|
||||
|
@ -52,7 +48,7 @@ def configure_alembic(config: Config):
|
|||
logger.debug(f"Adding migration version path {directory}")
|
||||
migrations.append(str(directory.resolve()))
|
||||
except:
|
||||
logger.warning(f"Could not load migrations of plugin {plugin.name} for database migration.")
|
||||
logger.warning(f"Could not load migrations of plugin {entry_point.name} for database migration.")
|
||||
logger.debug("Plugin loading failed", exc_info=True)
|
||||
|
||||
# write back seperator (we changed it if neither seperator nor locations were specified)
|
||||
|
|
Loading…
Reference in New Issue