-
-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(webchat): migrate webchat data when dashboard username changes #7261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,13 +6,15 @@ | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| from astrbot import logger | ||||||||||||||||||||||||||||||
| from astrbot.core import DEMO_MODE | ||||||||||||||||||||||||||||||
| from astrbot.core.db import BaseDatabase | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| from .route import Response, Route, RouteContext | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| class AuthRoute(Route): | ||||||||||||||||||||||||||||||
| def __init__(self, context: RouteContext) -> None: | ||||||||||||||||||||||||||||||
| def __init__(self, context: RouteContext, db: BaseDatabase) -> None: | ||||||||||||||||||||||||||||||
| super().__init__(context) | ||||||||||||||||||||||||||||||
| self.db = db | ||||||||||||||||||||||||||||||
| self.routes = { | ||||||||||||||||||||||||||||||
| "/auth/login": ("POST", self.login), | ||||||||||||||||||||||||||||||
| "/auth/account/edit": ("POST", self.edit_account), | ||||||||||||||||||||||||||||||
|
|
@@ -72,9 +74,15 @@ async def edit_account(self): | |||||||||||||||||||||||||||||
| if confirm_pwd != new_pwd: | ||||||||||||||||||||||||||||||
| return Response().error("两次输入的新密码不一致").__dict__ | ||||||||||||||||||||||||||||||
| self.config["dashboard"]["password"] = new_pwd | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| old_username = self.config["dashboard"]["username"] | ||||||||||||||||||||||||||||||
| if new_username: | ||||||||||||||||||||||||||||||
| self.config["dashboard"]["username"] = new_username | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Migrate webchat user data before saving config to keep them in sync. | ||||||||||||||||||||||||||||||
| if new_username and new_username != old_username: | ||||||||||||||||||||||||||||||
| await self.db.migrate_user_webchat_data(old_username, new_username) | ||||||||||||||||||||||||||||||
|
Comment on lines
+78
to
+84
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The dashboard username is updated in the
Suggested change
References
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| self.config.save_config() | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| return Response().ok(None, "修改成功").__dict__ | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The migration is missing several critical tables and columns that store webchat user identifiers. Specifically,
PlatformMessageHistory.user_id,ProviderStat.umo,PlatformSession.session_id, andSessionProjectRelation.session_idshould also be updated to ensure chat history, statistics, and project associations remain consistent after a username change. Additionally, adding a more specific filter to theWHEREclause (checking for the presence ofold_fragment) improves efficiency and prevents unnecessary updates.