mirror of
https://github.com/maubot/maubot.git
synced 2024-10-01 01:06:10 -04:00
Add db table for plugin files
This commit is contained in:
parent
8a711e0c8e
commit
ab88568d08
@ -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")
|
15
maubot/db.py
15
maubot/db.py
@ -36,7 +36,6 @@ class DBPlugin(Base):
|
||||
primary_user: UserID = Column(String(255),
|
||||
ForeignKey("client.id", onupdate="CASCADE", ondelete="RESTRICT"),
|
||||
nullable=False)
|
||||
config: str = Column(Text, nullable=False, default='')
|
||||
|
||||
@classmethod
|
||||
def all(cls) -> Iterable['DBPlugin']:
|
||||
@ -47,6 +46,20 @@ class DBPlugin(Base):
|
||||
return cls._select_one_or_none(cls.c.id == id)
|
||||
|
||||
|
||||
class DBPluginFile(Base):
|
||||
__tablename__ = "plugin_file"
|
||||
|
||||
plugin_id: str = Column(String(255),
|
||||
ForeignKey("plugin.id", onupdate="CASCADE", ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
file_name: str = Column(String(255), primary_key=True)
|
||||
content: str = Column(Text, nullable=False, default="")
|
||||
|
||||
@classmethod
|
||||
def all_for_plugin(cls, id: str) -> Iterable['DBPluginFile']:
|
||||
return cls._select_all(cls.c.plugin_id == id)
|
||||
|
||||
|
||||
class DBClient(Base):
|
||||
__tablename__ = "client"
|
||||
|
||||
|
@ -84,4 +84,3 @@ class PrefixResource(web.Resource):
|
||||
|
||||
def raw_match(self, path: str) -> bool:
|
||||
return path and path.startswith(self._prefix)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user