-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from difizen/ximo_dev
feat(api): add plugin database & api
- Loading branch information
Showing
9 changed files
with
562 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
"""add plugin table | ||
Revision ID: ac21c38c5e56 | ||
Revises: 5918599719a1 | ||
Create Date: 2024-07-02 09:56:29.437606 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = 'ac21c38c5e56' | ||
down_revision: Union[str, None] = '5918599719a1' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('plugin', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('plugin_type', sa.Integer(), nullable=False), | ||
sa.Column('created_by', sa.Integer(), nullable=True), | ||
sa.Column('created_at', sa.DateTime(), nullable=False), | ||
sa.Column('updated_by', sa.Integer(), nullable=True), | ||
sa.Column('updated_at', sa.DateTime(), nullable=False), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_table('plugin_config', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('name', sa.String(length=255), nullable=False), | ||
sa.Column('avatar', sa.String(length=255), nullable=True), | ||
sa.Column('description', sa.Text(), nullable=True), | ||
sa.Column('plugin_id', sa.Integer(), nullable=True), | ||
sa.Column('is_draft', sa.Boolean(), nullable=False), | ||
sa.Column('created_by', sa.Integer(), nullable=True), | ||
sa.Column('created_at', sa.DateTime(), nullable=False), | ||
sa.Column('updated_by', sa.Integer(), nullable=True), | ||
sa.Column('updated_at', sa.DateTime(), nullable=False), | ||
sa.ForeignKeyConstraint(['plugin_id'], ['plugin.id'], ), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_table('plugin_api', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('plugin_config_id', sa.Integer(), nullable=True), | ||
sa.Column('description', sa.Text(), nullable=True), | ||
sa.Column('openapi_desc', sa.Text(), nullable=True), | ||
sa.Column('disabled', sa.Boolean(), nullable=False), | ||
sa.Column('created_by', sa.Integer(), nullable=True), | ||
sa.Column('created_at', sa.DateTime(), nullable=False), | ||
sa.Column('updated_by', sa.Integer(), nullable=True), | ||
sa.Column('updated_at', sa.DateTime(), nullable=False), | ||
sa.ForeignKeyConstraint(['plugin_config_id'], [ | ||
'plugin_config.id'], ), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.alter_column('messages', 'message_type', | ||
type_=sa.VARCHAR(length=50), | ||
existing_type=sa.Enum( | ||
'MARKDOWN', 'TEXT', name='messagetype'), | ||
existing_nullable=False) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column('messages', 'message_type', | ||
existing_type=sa.Enum( | ||
'MARKDOWN', 'TEXT', name='messagetype'), | ||
type_=sa.VARCHAR(length=50), | ||
existing_nullable=False) | ||
op.drop_table('plugin_api') | ||
op.drop_table('plugin_config') | ||
op.drop_table('plugin') | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from typing import Optional | ||
from pydantic import BaseModel | ||
from datetime import datetime | ||
|
||
from sqlalchemy import ( | ||
Column, | ||
Integer, | ||
DateTime, | ||
) | ||
|
||
from db import Base | ||
from models.plugin_config import PluginConfigModel | ||
|
||
|
||
class PluginORM(Base): | ||
''' | ||
plugin database model | ||
''' | ||
__tablename__ = "plugin" | ||
id = Column(Integer, primary_key=True) | ||
plugin_type = Column(Integer, nullable=False) # 插件创建类型 | ||
created_by = Column(Integer) | ||
created_at = Column( | ||
DateTime(), nullable=False, default=datetime.now | ||
) | ||
updated_by = Column(Integer) | ||
updated_at = Column(DateTime(), | ||
nullable=False, onupdate=datetime.now) | ||
# statistic_data = Column(JSON) # 保留字段,用于存储诸如 被多少个bot 引用了 | ||
|
||
|
||
class PluginCreate(BaseModel): | ||
''' | ||
plugin create | ||
''' | ||
plugin_type: int | ||
|
||
|
||
class PluginUpdate(BaseModel): | ||
''' | ||
plugin update | ||
''' | ||
id: int | ||
plugin_type: int | ||
|
||
|
||
class PluginModel(PluginCreate): | ||
''' | ||
plugin | ||
''' | ||
id: int | ||
plugin_type: int | ||
created_by: int | ||
created_at: datetime | ||
updated_by: int | ||
updated_at: datetime | ||
draft: Optional[PluginConfigModel] = None | ||
|
||
class Config: | ||
from_attributes = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
from typing import Optional | ||
from pydantic import BaseModel | ||
from datetime import datetime | ||
|
||
from sqlalchemy import ( | ||
Column, | ||
ForeignKey, | ||
Integer, | ||
DateTime, | ||
Text, | ||
Boolean | ||
) | ||
|
||
from db import Base | ||
|
||
|
||
class PluginApiORM(Base): | ||
''' | ||
plugin api model | ||
''' | ||
__tablename__ = "plugin_api" | ||
id = Column(Integer, primary_key=True) | ||
plugin_config_id = Column(Integer, ForeignKey( | ||
"plugin_config.id"), nullable=True) | ||
description = Column(Text) # API 描述 | ||
openapi_desc = Column(Text) # openapi 先调研 | ||
# request_params = Column(JSON) # 入参 | ||
# response_params = Column(JSON) # 出参 | ||
# debug_example = Column(JSON) # 调试示例 | ||
# debug_example_status = Column(Integer) # 调试示例状态 | ||
# debug_status = Column(Integer) # 调试状态 | ||
disabled = Column(Boolean, nullable=False, default=True) | ||
# online_status = Column(Integer) # 服务状态 | ||
# path = Column(String(255)) #路径 | ||
created_by = Column(Integer) | ||
created_at = Column( | ||
DateTime(), nullable=False, default=datetime.now, | ||
) | ||
updated_by = Column(Integer) | ||
updated_at = Column(DateTime(), | ||
nullable=False, onupdate=datetime.now) | ||
# statistic_data = Column(JSON) # 保留字段,用于存储诸如 被多少个bot 引用了 | ||
|
||
|
||
class PluginApiCreate(BaseModel): | ||
''' | ||
plugin api create | ||
''' | ||
plugin_config_id: int | ||
description: str | ||
openapi_desc: str | ||
disabled: bool | ||
created_by: int | ||
created_at: datetime | ||
updated_by: int | ||
updated_at: datetime | ||
|
||
|
||
class PluginApiUpdate(BaseModel): | ||
''' | ||
plugin api update | ||
''' | ||
id: int | ||
description: str | ||
openapi_desc: str | ||
disabled: bool | ||
|
||
|
||
class PluginApiModel(PluginApiCreate): | ||
''' | ||
plugin api | ||
''' | ||
id: int | ||
plugin_config_id: int | ||
description: str | ||
openapi_desc: str | ||
disabled: bool | ||
created_by: int | ||
created_at: datetime | ||
updated_by: int | ||
updated_at: datetime | ||
|
||
class Config: | ||
from_attributes = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from typing import Optional | ||
from datetime import datetime | ||
from pydantic import BaseModel | ||
from sqlalchemy import ( | ||
Boolean, | ||
Column, | ||
Integer, | ||
DateTime, | ||
ForeignKey, | ||
String, | ||
Text, | ||
) | ||
|
||
from db import Base | ||
|
||
|
||
class PluginConfigORM(Base): | ||
''' | ||
plugin config database model | ||
''' | ||
__tablename__ = "plugin_config" | ||
id = Column(Integer, primary_key=True) | ||
name = Column(String(255), nullable=False) # 插件名字 | ||
avatar = Column(String(255)) # 插件图标 | ||
description = Column(Text) # 插件描述 | ||
# meta_info = Column(JSON) # 插件元信息,包含 api url,service_token,oauth_info 等 | ||
plugin_id = Column(Integer, ForeignKey("plugin.id"), nullable=True) | ||
is_draft = Column(Boolean, nullable=False) # 是否为草稿 | ||
# openapi_desc = Column(Text) # openapi 先调研 | ||
# plugin_desc = Column(Text) | ||
created_by = Column(Integer) | ||
created_at = Column( | ||
DateTime(), nullable=False, default=datetime.now, | ||
) | ||
updated_by = Column(Integer) | ||
updated_at = Column(DateTime(), | ||
nullable=False, onupdate=datetime.now) | ||
|
||
|
||
class PluginConfigCreate(BaseModel): | ||
''' | ||
plugin config create | ||
''' | ||
plugin_id: int | ||
name: str | ||
avatar: str | ||
description: str | ||
|
||
is_draft: Optional[bool] | ||
|
||
|
||
class PluginConfigUpdate(BaseModel): | ||
''' | ||
plugin config update | ||
''' | ||
id: int | ||
is_draft: Optional[bool] | ||
name: str | ||
avatar: str | ||
description: str | ||
|
||
|
||
class PluginConfigModel(PluginConfigCreate): | ||
''' | ||
plugin config | ||
''' | ||
id: int | ||
name: str | ||
avatar: str | ||
description: str | ||
|
||
plugin_id: int | ||
created_by: int | ||
created_at: datetime | ||
updated_by: int | ||
updated_at: datetime | ||
|
||
class Config: | ||
from_attributes = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.