Compare commits

..

11 Commits

Author SHA1 Message Date
Ferdinand Thiessen 507eb8d711 fix(migrations): Fix rebase issues
ci/woodpecker/push/lint Pipeline was successful Details
ci/woodpecker/push/test Pipeline was successful Details
ci/woodpecker/pr/lint Pipeline was successful Details
ci/woodpecker/pr/test Pipeline was successful Details
2022-02-23 15:24:24 +01:00
Ferdinand Thiessen 693978a5f9 fix(app): Skip plugins with not satisfied dependencies. 2022-02-23 15:24:24 +01:00
Ferdinand Thiessen 015ef353d9 fix(plugins): Fix plugin version for plugin list API endpoint 2022-02-23 15:24:24 +01:00
Ferdinand Thiessen 0bfc551450 feat(cli): Added CLI command for handling plugins
* Install / Uninstall plugins
* List plugins
2022-02-23 15:24:24 +01:00
Ferdinand Thiessen 4248405462 feat(plugins): Identify plugins by id, migrations must be provided at defined location, add utils for plugin functions 2022-02-23 15:24:24 +01:00
Ferdinand Thiessen f5c7e59162 feat(docs): Add documentation on how to install tables
Also various documentation fixed and improvments
2022-02-23 15:24:21 +01:00
Ferdinand Thiessen 5cf54c1a08 feat(db): Add migrations support to plugins
* Add initial migrations for core Flaschengeist
* Add migrations to balance
* Add migrations to pricelist
2022-02-23 15:21:37 +01:00
Ferdinand Thiessen f2ea2a8fa5 fix(db): Add __repr__ to custom column types, same as done by SQLAlchemy 2022-02-23 15:21:37 +01:00
Ferdinand Thiessen 4d972defdc feat(db): Add database migration support, implements #19
Migrations allow us to keep track of database changes and upgrading databases if needed.
2022-02-23 15:21:37 +01:00
Ferdinand Thiessen 6f35e17fba feat(plugins): Load metadata from entry points / distribution
ci/woodpecker/push/lint Pipeline was successful Details
ci/woodpecker/push/test Pipeline was successful Details
ci/woodpecker/pr/lint Pipeline was successful Details
ci/woodpecker/pr/test Pipeline was successful Details
2022-02-23 15:20:31 +01:00
Ferdinand Thiessen 2f4472e708 feat(docs): Added more documentation on plugins
ci/woodpecker/push/lint Pipeline was successful Details
ci/woodpecker/push/test Pipeline was successful Details
2022-02-23 15:19:45 +01:00
4 changed files with 61 additions and 23 deletions

3
.gitignore vendored
View File

@ -67,7 +67,8 @@ instance/
# Sphinx documentation # Sphinx documentation
docs/_build/ docs/_build/
docs/ # pdoc
docs/html
# PyBuilder # PyBuilder
target/ target/

View File

@ -0,0 +1,57 @@
# Plugin Development
## File Structure
- your_plugin/
- __init__.py
- ...
- migrations/ (optional)
- ...
- setup.cfg
The basic layout of a plugin is quite simple, you will only need the `setup.cfg` or `setup.py` and
the package containing your plugin code, at lease a `__init__.py` file with your `Plugin` class.
If you use custom database tables you need to provide a `migrations` directory within your package,
see next section.
## Database Tables / Migrations
To allow upgrades of installed plugins, the database is versioned and handled
through [Alembic](https://alembic.sqlalchemy.org/en/latest/index.html) migrations.
Each plugin, which uses custom database tables, is represented as an other base.
So you could simply follow the Alembic tutorial on [how to work with multiple bases](https://alembic.sqlalchemy.org/en/latest/branches.html#creating-a-labeled-base-revision).
A quick overview on how to work with migrations for your plugin:
$ flaschengeist db revision -m "Create my super plugin" \
--head=base --branch-label=myplugin_name --version-path=your/plugin/migrations
This would add a new base named `myplugin_name`, which should be the same as the pypi name of you plugin.
If your tables depend on an other plugin or a specific base version you could of cause add
--depends-on=VERSION
or
--depends-on=other_plugin
### Plugin Removal and Database Tables
As generic downgrades are most often hard to write, your plugin is not required to provide such functionallity.
For Flaschengeist only instable versions provide meaningful downgrade migrations down to the latest stable version.
So this means if you do not provide downgrades you must at lease provide a series of migrations toward removal of
the database tables in case the users wants to delete the plugin.
(base) ----> 1.0 <----> 1.1 <----> 1.2
|
--> removal
After the removal step the database is stamped to to "remove" your
## Useful Hooks
There are some predefined hooks, which might get handy for you.
For more information, please refer to
- `flaschengeist.utils.hook.HookBefore` and
- `flaschengeist.utils.hook.HookAfter`

View File

@ -8,7 +8,7 @@ import subprocess
"--output", "--output",
"-o", "-o",
help="Documentation output path", help="Documentation output path",
default="./docs", default="./docs/html",
type=click.Path(file_okay=False, path_type=pathlib.Path), type=click.Path(file_okay=False, path_type=pathlib.Path),
) )
@click.pass_context @click.pass_context

View File

@ -1,27 +1,7 @@
"""Flaschengeist Plugins """Flaschengeist Plugins
## Custom database tables .. include:: docs/plugin_development.md
You can add tables by declaring them using the SQLAlchemy syntax,
then use Alembic to generate migrations for your tables.
This allows Flaschengeist to proper up- or downgrade the
database tables if an user updates your plugin.
migrations have to be provided in a directory called `migrations`
next to your plugin. E.G.
myplugin
- __init__.py
- other/
- ...
- migrations/
## Useful Hooks
There are some predefined hooks, which might get handy for you.
For more information, please refer to
- `flaschengeist.utils.hook.HookBefore` and
- `flaschengeist.utils.hook.HookAfter`
""" """
from typing import Optional from typing import Optional