Remove command_spec table
This commit is contained in:
parent
4b7c38ca2a
commit
b96d6e6a94
41
maubot/db.py
41
maubot/db.py
@ -13,40 +13,15 @@
|
|||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
from typing import Type
|
from sqlalchemy import Column, String, Boolean, ForeignKey, Text
|
||||||
from sqlalchemy import (Column, String, Boolean, ForeignKey, Text, TypeDecorator)
|
|
||||||
from sqlalchemy.orm import Query, scoped_session
|
from sqlalchemy.orm import Query, scoped_session
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
import json
|
|
||||||
|
|
||||||
from mautrix.types import UserID, FilterID, SyncToken, ContentURI
|
from mautrix.types import UserID, FilterID, SyncToken, ContentURI
|
||||||
from mautrix.client.api.types.util import Serializable
|
|
||||||
|
|
||||||
from .command_spec import CommandSpec
|
|
||||||
|
|
||||||
Base: declarative_base = declarative_base()
|
Base: declarative_base = declarative_base()
|
||||||
|
|
||||||
|
|
||||||
def make_serializable_alchemy(serializable_type: Type[Serializable]):
|
|
||||||
class SerializableAlchemy(TypeDecorator):
|
|
||||||
impl = Text
|
|
||||||
|
|
||||||
@property
|
|
||||||
def python_type(self):
|
|
||||||
return serializable_type
|
|
||||||
|
|
||||||
def process_literal_param(self, value: Serializable, _) -> str:
|
|
||||||
return json.dumps(value.serialize()) if value is not None else None
|
|
||||||
|
|
||||||
def process_bind_param(self, value: Serializable, _) -> str:
|
|
||||||
return json.dumps(value.serialize()) if value is not None else None
|
|
||||||
|
|
||||||
def process_result_value(self, value: str, _) -> serializable_type:
|
|
||||||
return serializable_type.deserialize(json.loads(value)) if value is not None else None
|
|
||||||
|
|
||||||
return SerializableAlchemy
|
|
||||||
|
|
||||||
|
|
||||||
class DBPlugin(Base):
|
class DBPlugin(Base):
|
||||||
query: Query
|
query: Query
|
||||||
__tablename__ = "plugin"
|
__tablename__ = "plugin"
|
||||||
@ -78,20 +53,6 @@ class DBClient(Base):
|
|||||||
avatar_url: ContentURI = Column(String(255), nullable=False, default="")
|
avatar_url: ContentURI = Column(String(255), nullable=False, default="")
|
||||||
|
|
||||||
|
|
||||||
class DBCommandSpec(Base):
|
|
||||||
query: Query
|
|
||||||
__tablename__ = "command_spec"
|
|
||||||
|
|
||||||
plugin: str = Column(String(255),
|
|
||||||
ForeignKey("plugin.id", onupdate="CASCADE", ondelete="CASCADE"),
|
|
||||||
primary_key=True)
|
|
||||||
client: UserID = Column(String(255),
|
|
||||||
ForeignKey("client.id", onupdate="CASCADE", ondelete="CASCADE"),
|
|
||||||
primary_key=True)
|
|
||||||
spec: CommandSpec = Column(make_serializable_alchemy(CommandSpec), nullable=False)
|
|
||||||
|
|
||||||
|
|
||||||
def init(session: scoped_session) -> None:
|
def init(session: scoped_session) -> None:
|
||||||
DBPlugin.query = session.query_property()
|
DBPlugin.query = session.query_property()
|
||||||
DBClient.query = session.query_property()
|
DBClient.query = session.query_property()
|
||||||
DBCommandSpec.query = session.query_property()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user