mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-04 02:26:11 +08:00
🚚 move db_migration code
This commit is contained in:
parent
9581887994
commit
88bb1d3698
@ -3,7 +3,7 @@ from nonebot_plugin_datastore.db import get_engine, post_db_init, pre_db_init
|
||||
from sqlalchemy import inspect, text
|
||||
|
||||
from .config.config_legacy import start_up as legacy_db_startup
|
||||
from .config.db import data_migrate
|
||||
from .config.db_migration import data_migrate
|
||||
from .scheduler.manager import init_scheduler
|
||||
|
||||
|
||||
|
@ -89,7 +89,7 @@ class DBConfig:
|
||||
select(Subscribe)
|
||||
.where(User.type == user_type, User.uid == user)
|
||||
.join(User)
|
||||
.options(selectinload(Subscribe.target)) # type:ignore
|
||||
.options(selectinload(Subscribe.target))
|
||||
)
|
||||
subs = (await session.scalars(query_stmt)).all()
|
||||
return subs
|
||||
|
@ -11,7 +11,10 @@ async def data_migrate():
|
||||
if config.available:
|
||||
logger.warning("You are still using legacy db, migrating to sqlite")
|
||||
all_subs: list[ConfigContent] = list(
|
||||
map(lambda item: ConfigContent(**item), config.get_all_subscribe().all())
|
||||
map(
|
||||
lambda item: ConfigContent(**item),
|
||||
config.get_all_subscribe().all(),
|
||||
)
|
||||
)
|
||||
async with AsyncSession(get_engine()) as sess:
|
||||
user_to_create = []
|
@ -30,7 +30,7 @@ class Target(Model):
|
||||
platform_name: Mapped[str] = mapped_column(String(20))
|
||||
target: Mapped[str] = mapped_column(String(1024))
|
||||
target_name: Mapped[str] = mapped_column(String(1024))
|
||||
default_schedule_weight: Mapped[int | None] = mapped_column(default=10)
|
||||
default_schedule_weight: Mapped[int] = mapped_column(default=10)
|
||||
|
||||
subscribes: Mapped[list["Subscribe"]] = relationship(back_populates="target")
|
||||
time_weight: Mapped[list["ScheduleTimeWeight"]] = relationship(
|
||||
@ -40,10 +40,10 @@ class Target(Model):
|
||||
|
||||
class ScheduleTimeWeight(Model):
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
target_id: Mapped[int | None] = mapped_column(ForeignKey("nonebot_bison_target.id"))
|
||||
start_time: Mapped[datetime.time | None]
|
||||
end_time: Mapped[datetime.time | None]
|
||||
weight: Mapped[int | None]
|
||||
target_id: Mapped[int] = mapped_column(ForeignKey("nonebot_bison_target.id"))
|
||||
start_time: Mapped[datetime.time]
|
||||
end_time: Mapped[datetime.time]
|
||||
weight: Mapped[int]
|
||||
|
||||
target: Mapped[Target] = relationship(back_populates="time_weight")
|
||||
|
||||
@ -57,8 +57,8 @@ class Subscribe(Model):
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
target_id: Mapped[int | None] = mapped_column(ForeignKey("nonebot_bison_target.id"))
|
||||
user_id: Mapped[int | None] = mapped_column(ForeignKey("nonebot_bison_user.id"))
|
||||
target_id: Mapped[int] = mapped_column(ForeignKey("nonebot_bison_target.id"))
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("nonebot_bison_user.id"))
|
||||
categories: Mapped[list[Category]] = mapped_column(JSON)
|
||||
tags: Mapped[list[Tag]] = mapped_column(JSON)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user