mirror of
https://github.com/maubot/maubot
synced 2025-08-29 15:40:37 +00:00
Add db table for plugin files
This commit is contained in:
parent
8a711e0c8e
commit
ab88568d08
3 changed files with 54 additions and 2 deletions
|
@ -0,0 +1,40 @@
|
|||
"""Let plugins have multiple files
|
||||
|
||||
Revision ID: 6b66c1600d16
|
||||
Revises: d295f8dcfa64
|
||||
Create Date: 2020-01-02 01:30:51.622962
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "6b66c1600d16"
|
||||
down_revision = "d295f8dcfa64"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
plugin_file: sa.Table = op.create_table(
|
||||
"plugin_file",
|
||||
sa.Column("plugin_id", sa.String(length=255), nullable=False),
|
||||
sa.Column("file_name", sa.String(length=255), nullable=False),
|
||||
sa.Column("content", sa.Text(), nullable=False),
|
||||
sa.ForeignKeyConstraint(("plugin_id",), ["plugin.id"], onupdate="CASCADE",
|
||||
ondelete="CASCADE"),
|
||||
sa.PrimaryKeyConstraint("plugin_id", "file_name"))
|
||||
|
||||
conn: sa.engine.Connection = op.get_bind()
|
||||
conn.execute(plugin_file.insert().values([{
|
||||
"plugin_id": plugin_id,
|
||||
"file_name": "config.yaml",
|
||||
"content": config
|
||||
} for plugin_id, config in conn.execute("SELECT id, config FROM plugin").fetchall()]))
|
||||
|
||||
op.drop_column("plugin", "config")
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.add_column("plugin", sa.Column("config", sa.TEXT(), autoincrement=False, nullable=False))
|
||||
op.drop_table("plugin_file")
|
Loading…
Add table
Add a link
Reference in a new issue