Skip to content
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

迁移方式求助 #1

Open
F1Justin opened this issue Dec 28, 2024 · 4 comments
Open

迁移方式求助 #1

F1Justin opened this issue Dec 28, 2024 · 4 comments

Comments

@F1Justin
Copy link

我希望将nonebot-plugin-chatrecorder从0.6迁移到0.7版本。我首先安装了nonebot-plugin-uninfo插件,然后将此repo的nonebot_session_to_uninfo文件夹下载并放在nonebot的自定义插件目录中,随后更新了nonebot-plugin-chatrecorder插件,输入nb orm upgrade出现报错一,卸载nonebot-plugin-uninfo之后运行又出现报错二,好奇正确的迁移方式是怎么样的(
报错一:

Traceback (most recent call last):
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py", line 534, in _prepare_and_execute
    self._rows = deque(await prepared_stmt.fetch(*parameters))
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/asyncpg/prepared_stmt.py", line 176, in fetch
    data = await self.__bind_execute(args, 0, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/asyncpg/prepared_stmt.py", line 267, in __bind_execute
    data, status, _ = await self.__do_execute(
                      ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/asyncpg/prepared_stmt.py", line 256, in __do_execute
    return await executor(protocol)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "asyncpg/protocol/protocol.pyx", line 206, in bind_execute
asyncpg.exceptions.DuplicateTableError: relation "unique_session" already exists

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
    self.dialect.do_execute(
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/engine/default.py", line 941, in do_execute
    cursor.execute(statement, parameters)
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py", line 568, in execute
    self._adapt_connection.await_(
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 132, in await_only
    return current.parent.switch(awaitable)  # type: ignore[no-any-return,attr-defined] # noqa: E501
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 196, in greenlet_spawn
    value = await result
            ^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py", line 546, in _prepare_and_execute
    self._handle_exception(error)
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py", line 497, in _handle_exception
    self._adapt_connection._handle_exception(error)
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py", line 780, in _handle_exception
    raise translated_error from error
sqlalchemy.dialects.postgresql.asyncpg.AsyncAdapt_asyncpg_dbapi.ProgrammingError: <class 'asyncpg.exceptions.DuplicateTableError'>: relation "unique_session" already exists

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<string>", line 29, in <module>
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot_plugin_orm/__main__.py", line 283, in main
    orm(*args, **kwargs)
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot_plugin_orm/__main__.py", line 86, in wrapper
    return f(ctx.obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot_plugin_orm/__main__.py", line 175, in upgrade
    return migrate.upgrade(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot_plugin_orm/migrate.py", line 662, in upgrade
    script.run_env()
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/alembic/script/base.py", line 586, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/alembic/util/pyfiles.py", line 95, in load_python_file
    module = load_module_py(module_id, path)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/alembic/util/pyfiles.py", line 113, in load_module_py
    spec.loader.exec_module(module)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot_plugin_orm/templates/generic/env.py", line 88, in <module>
    asyncio.run(coro)
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot_plugin_orm/templates/generic/env.py", line 79, in run_migrations_online
    await connection.run_sync(do_run_migrations)
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/ext/asyncio/engine.py", line 886, in run_sync
    return await greenlet_spawn(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 203, in greenlet_spawn
    result = context.switch(value)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot_plugin_orm/templates/generic/env.py", line 69, in do_run_migrations
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/alembic/runtime/environment.py", line 946, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/alembic/runtime/migration.py", line 628, in run_migrations
    step.migration_fn(**kw)
  File "/tmp/tmpveb35zsn/nonebot_plugin_uninfo/14175fde8186_init_db.py", line 58, in upgrade
  File "<string>", line 8, in create_table
  File "<string>", line 3, in create_table
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/alembic/operations/ops.py", line 1318, in create_table
    return operations.invoke(op)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/alembic/operations/base.py", line 442, in invoke
    return fn(self, operation)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/alembic/operations/toimpl.py", line 143, in create_table
    operations.impl.create_table(table, **kw)
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/alembic/ddl/impl.py", line 369, in create_table
    self._exec(schema.CreateTable(table, **kw))
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/alembic/ddl/impl.py", line 210, in _exec
    return conn.execute(construct, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1418, in execute
    return meth(
           ^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/sql/ddl.py", line 180, in _execute_on_connection
    return connection._execute_ddl(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1529, in _execute_ddl
    ret = self._execute_context(
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
    return self._exec_single_context(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
    self._handle_dbapi_exception(
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 2355, in _handle_dbapi_exception
    raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
    self.dialect.do_execute(
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/engine/default.py", line 941, in do_execute
    cursor.execute(statement, parameters)
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py", line 568, in execute
    self._adapt_connection.await_(
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 132, in await_only
    return current.parent.switch(awaitable)  # type: ignore[no-any-return,attr-defined] # noqa: E501
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 196, in greenlet_spawn
    value = await result
            ^^^^^^^^^^^^
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py", line 546, in _prepare_and_execute
    self._handle_exception(error)
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py", line 497, in _handle_exception
    self._adapt_connection._handle_exception(error)
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py", line 780, in _handle_exception
    raise translated_error from error
sqlalchemy.exc.ProgrammingError: (sqlalchemy.dialects.postgresql.asyncpg.ProgrammingError) <class 'asyncpg.exceptions.DuplicateTableError'>: relation "unique_session" already exists
[SQL: 
CREATE TABLE nonebot_plugin_uninfo_sessionmodel (
	id SERIAL NOT NULL, 
	bot_persist_id INTEGER NOT NULL, 
	scene_persist_id INTEGER NOT NULL, 
	user_persist_id INTEGER NOT NULL, 
	member_data JSON, 
	CONSTRAINT pk_nonebot_plugin_uninfo_sessionmodel PRIMARY KEY (id), 
	CONSTRAINT unique_session UNIQUE (bot_persist_id, scene_persist_id, user_persist_id)
)

]
(Background on this error at: https://sqlalche.me/e/20/f405)

报错二:

12-28 17:36:24 [ERROR] nonebot | Failed to import "nonebot_plugin_uninfo"
Traceback (most recent call last):
  File "<string>", line 15, in <module>
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot/plugin/load.py", line 131, in load_from_toml
    return load_all_plugins(plugins, plugin_dirs)
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot/plugin/load.py", line 65, in load_all_plugins
    return manager.load_all_plugins()
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot/plugin/manager.py", line 203, in load_all_plugins
    return set(
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot/plugin/manager.py", line 204, in <genexpr>
    filter(None, (self.load_plugin(name) for name in self.available_plugins))
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot/plugin/manager.py", line 167, in load_plugin
    module = importlib.import_module(self._third_party_plugin_ids[name])
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot/plugin/manager.py", line 255, in exec_module
    super().exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot_plugin_chatrecorder/__init__.py", line 5, in <module>
    require("nonebot_plugin_uninfo")
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot/plugin/load.py", line 181, in require
    plugin = manager.load_plugin(name)
> File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot/plugin/manager.py", line 167, in load_plugin
    module = importlib.import_module(self._third_party_plugin_ids[name])
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'nonebot_plugin_uninfo'
12-28 17:36:24 [ERROR] nonebot | Failed to import "nonebot_plugin_chatrecorder"
Traceback (most recent call last):
  File "<string>", line 15, in <module>
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot/plugin/load.py", line 131, in load_from_toml
    return load_all_plugins(plugins, plugin_dirs)
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot/plugin/load.py", line 65, in load_all_plugins
    return manager.load_all_plugins()
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot/plugin/manager.py", line 203, in load_all_plugins
    return set(
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot/plugin/manager.py", line 204, in <genexpr>
    filter(None, (self.load_plugin(name) for name in self.available_plugins))
> File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot/plugin/manager.py", line 167, in load_plugin
    module = importlib.import_module(self._third_party_plugin_ids[name])
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot/plugin/manager.py", line 255, in exec_module
    super().exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot_plugin_chatrecorder/__init__.py", line 5, in <module>
    require("nonebot_plugin_uninfo")
  File "/home/justin/lily/.venv/lib/python3.11/site-packages/nonebot/plugin/load.py", line 188, in require
    raise RuntimeError(f'Cannot load plugin "{name}"!')
RuntimeError: Cannot load plugin "nonebot_plugin_uninfo"!
@MeetWq
Copy link
Member

MeetWq commented Dec 28, 2024

这不是 nb 插件,请用 pip 安装

nonebot-plugin-uninfo 插件是需要的

@MeetWq
Copy link
Member

MeetWq commented Dec 28, 2024

上面的报错似乎是因为 nonebot-plugin-uninfo 和 nonebot-plugin-session-orm 是数据库表有些冲突,可以先等等

@F1Justin
Copy link
Author

已通过pip安装,不过还是报错(Background on this error at: https://sqlalche.me/e/20/f405)之类的

@MeetWq
Copy link
Member

MeetWq commented Jan 2, 2025

现在你可以先降级 nonebot-plugin-chatrecorder 到 0.6.x,同时升级 nonebot-plugin-session-orm 到 0.2.1,运行 nb orm upgrade 升级数据库;

然后再升级 nonebot-plugin-chatrecorder 完成迁移

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants