mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-07-16 13:22:59 +08:00
🗃️ add user_target column
This commit is contained in:
parent
e8d83c5255
commit
d535f5212d
@ -1,7 +1,9 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from nonebot_plugin_datastore import get_plugin_data
|
from nonebot_plugin_datastore import get_plugin_data
|
||||||
|
from nonebot_plugin_saa.utils import PlatformTarget
|
||||||
from sqlalchemy import JSON, ForeignKey, String, UniqueConstraint
|
from sqlalchemy import JSON, ForeignKey, String, UniqueConstraint
|
||||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||||
|
|
||||||
@ -17,6 +19,7 @@ class User(Model):
|
|||||||
id: Mapped[int] = mapped_column(primary_key=True)
|
id: Mapped[int] = mapped_column(primary_key=True)
|
||||||
type: Mapped[str] = mapped_column(String(20))
|
type: Mapped[str] = mapped_column(String(20))
|
||||||
uid: Mapped[int]
|
uid: Mapped[int]
|
||||||
|
user_target: Mapped[Optional[dict]] = mapped_column(JSON, nullable=True)
|
||||||
|
|
||||||
subscribes: Mapped[list["Subscribe"]] = relationship(back_populates="user")
|
subscribes: Mapped[list["Subscribe"]] = relationship(back_populates="user")
|
||||||
|
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
"""add user_target
|
||||||
|
|
||||||
|
Revision ID: 632b8086bc2b
|
||||||
|
Revises: aceef470d69c
|
||||||
|
Create Date: 2023-03-20 00:39:30.199915
|
||||||
|
|
||||||
|
"""
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = "632b8086bc2b"
|
||||||
|
down_revision = "aceef470d69c"
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table("nonebot_bison_user", schema=None) as batch_op:
|
||||||
|
batch_op.add_column(sa.Column("user_target", sa.JSON(), nullable=True))
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table("nonebot_bison_user", schema=None) as batch_op:
|
||||||
|
batch_op.drop_column("user_target")
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
51
nonebot_bison/config/migrations/a5466912fad0_map_user.py
Normal file
51
nonebot_bison/config/migrations/a5466912fad0_map_user.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
"""map user
|
||||||
|
|
||||||
|
Revision ID: a5466912fad0
|
||||||
|
Revises: 632b8086bc2b
|
||||||
|
Create Date: 2023-03-20 01:14:42.623789
|
||||||
|
|
||||||
|
"""
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
|
from sqlalchemy.ext.automap import automap_base
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = "a5466912fad0"
|
||||||
|
down_revision = "632b8086bc2b"
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
Base = automap_base()
|
||||||
|
Base.prepare(op.get_bind())
|
||||||
|
User = Base.classes.nonebot_bison_user
|
||||||
|
with Session(op.get_bind()) as sess:
|
||||||
|
users = sess.scalars(sa.select(User)).all()
|
||||||
|
for user in users:
|
||||||
|
if user.type == "group":
|
||||||
|
user.user_target = {"platform_type": "QQ Group", "group_id": user.uid}
|
||||||
|
elif user.type == "private":
|
||||||
|
user.user_target = {"platform_type": "QQ Private", "user_id": user.uid}
|
||||||
|
else:
|
||||||
|
sess.delete(user)
|
||||||
|
sess.add_all(users)
|
||||||
|
sess.commit()
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
Base = automap_base()
|
||||||
|
Base.prepare(op.get_bind())
|
||||||
|
User = Base.classes.nonebot_bison_user
|
||||||
|
with Session(op.get_bind()) as sess:
|
||||||
|
users = sess.scalars(sa.select(User)).all()
|
||||||
|
for user in users:
|
||||||
|
if user.user_target["platform_type"] == "QQ Group":
|
||||||
|
user.uid = user.user_target["group_id"]
|
||||||
|
user.type = "group"
|
||||||
|
else:
|
||||||
|
user.uid = user.user_target["user_id"]
|
||||||
|
user.type = "private"
|
||||||
|
sess.add_all(users)
|
||||||
|
sess.commit()
|
1552
poetry.lock
generated
1552
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@ -34,6 +34,7 @@ nonebot-adapter-onebot = "^2.0.0-beta.1"
|
|||||||
nonebot-plugin-htmlrender = ">=0.2.0"
|
nonebot-plugin-htmlrender = ">=0.2.0"
|
||||||
nonebot-plugin-datastore = "^0.6.2"
|
nonebot-plugin-datastore = "^0.6.2"
|
||||||
nonebot-plugin-apscheduler = "^0.2.0"
|
nonebot-plugin-apscheduler = "^0.2.0"
|
||||||
|
nonebot-plugin-send-anything-anywhere = "^0.2.1"
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
[tool.poetry.group.dev.dependencies]
|
||||||
ipdb = "^0.13.4"
|
ipdb = "^0.13.4"
|
||||||
@ -49,6 +50,7 @@ nonebot2 = { extras = ["fastapi"], version = ">=2.0.0-rc.2" }
|
|||||||
pytest-mock = "^3.10.0"
|
pytest-mock = "^3.10.0"
|
||||||
nonebug = { git = "https://github.com/nonebot/nonebug.git", rev = "master" }
|
nonebug = { git = "https://github.com/nonebot/nonebug.git", rev = "master" }
|
||||||
pytest-xdist = { extras = ["psutil"], version = "^3.1.0" }
|
pytest-xdist = { extras = ["psutil"], version = "^3.1.0" }
|
||||||
|
nb-cli = "^1.0.5"
|
||||||
|
|
||||||
[tool.poetry.extras]
|
[tool.poetry.extras]
|
||||||
cli = ["anyio", "click", "typing-extensions"]
|
cli = ["anyio", "click", "typing-extensions"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user