创建SQL表的时候无法select任何数据

* 描述问题

SQL数据表无法读取数据库,报错SQLITE_ERROR: no such table: problem

* 运行环境

  • NocoBase 版本: v1.3.35-beta(实际上是v1.3.36,右上角处的版本号不太对)
    中间做过一次从1.3.35到1.3.36的升级
  • 数据库种类与版本: sqlite
  • 操作系统: Ubuntu 24.04
    -浏览器及版本: 版本 130.0.6723.69(正式版本) (64 位)
  • 部署方式: git源码
  • Docker 镜像版本:
  • NodeJS 版本: Node.js v18.19.1.

如何重现

演示站无法重现,行为正常。本地创建SQL表的时候就会出现该问题

预期行为

截图

日志

2024-10-25 19:48:18 [error] SQLITE_ERROR: no such table: users           meta={"err":"Error\n    at Database.<anonymous> (/home/geekcmore/ctf/dev/project/platform/my-nocobase/node_modules/sequelize/src/dialects/sqlite/query.js:236:27)\n    at <anonymous> (/home/geekcmore/ctf/dev/project/platform/my-nocobase/node_modules/sequelize/src/dialects/sqlite/query.js:234:50)\n    at new Promise (<anonymous>)\n    at Query.run (/home/geekcmore/ctf/dev/project/platform/my-nocobase/node_modules/sequelize/src/dialects/sqlite/query.js:234:12)\n    at <anonymous> (/home/geekcmore/ctf/dev/project/platform/my-nocobase/node_modules/sequelize/src/sequelize.js:650:28)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at Proxy.select (/home/geekcmore/ctf/dev/project/platform/my-nocobase/node_modules/sequelize/src/dialects/abstract/query-interface.js:1001:12)\n    at Proxy.findAll (/home/geekcmore/ctf/dev/project/platform/my-nocobase/node_modules/sequelize/src/model.js:1824:21)\n    at execute (/home/geekcmore/ctf/dev/project/platform/my-nocobase/packages/plugins/@nocobase/plugin-collection-sql/src/server/resources/sql.ts:52:20)\n    at middleware (/home/geekcmore/ctf/dev/project/platform/my-nocobase/packages/plugins/@nocobase/plugin-workflow-action-trigger/src/server/ActionTrigger.ts:53:5)"} module=sqlCollection submodule=execute method=error-handler app=main reqId=89eac610-f7d4-4707-95de-9732bd4a721e dataSourceKey=main
2024-10-25 19:48:18 [error] response /api/sqlCollection:execute          method=POST path=/api/sqlCollection:execute res=[{"message":"SQLITE_ERROR: no such table: users"}] action={"actionName":"execute","resourceName":"sqlCollection","params":{"resourceName":"sqlCollection","actionName":"execute","values":{"sql":"select * from users"}}} userId=1 status=500 cost=5 app=main reqId=89eac610-f7d4-4707-95de-9732bd4a721e
2024-10-25 19:48:19 [info]  request POST /api/sqlCollection:execute      method=POST path=/api/sqlCollection:execute req={"header":{"x-role":"root","x-hostname":"localhost","x-timezone":"+08:00","x-locale":"zh-CN","x-authenticator":"basic"}} app=main reqId=3bc7c670-351e-4ddd-a047-2d470d4200b8
2024-10-25 19:48:19 [debug] ctx permission                               meta={"can":{"role":"root","resource":"sqlCollection","action":"execute"},"resourceName":"sqlCollection","actionName":"execute","skip":true} module=sqlCollection submodule=execute app=main reqId=3bc7c670-351e-4ddd-a047-2d470d4200b8 dataSourceKey=main
2024-10-25 19:48:19 [debug] acl params                                   module=sqlCollection submodule=execute app=main reqId=3bc7c670-351e-4ddd-a047-2d470d4200b8 dataSourceKey=main
2024-10-25 19:48:19 [debug] acl parsedParams                             module=sqlCollection submodule=execute app=main reqId=3bc7c670-351e-4ddd-a047-2d470d4200b8 dataSourceKey=main
2024-10-25 19:48:19 [error] SQLITE_ERROR: no such table: users           meta={"err":"Error\n    at Database.<anonymous> (/home/geekcmore/ctf/dev/project/platform/my-nocobase/node_modules/sequelize/src/dialects/sqlite/query.js:236:27)\n    at <anonymous> (/home/geekcmore/ctf/dev/project/platform/my-nocobase/node_modules/sequelize/src/dialects/sqlite/query.js:234:50)\n    at new Promise (<anonymous>)\n    at Query.run (/home/geekcmore/ctf/dev/project/platform/my-nocobase/node_modules/sequelize/src/dialects/sqlite/query.js:234:12)\n    at <anonymous> (/home/geekcmore/ctf/dev/project/platform/my-nocobase/node_modules/sequelize/src/sequelize.js:650:28)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at Proxy.select (/home/geekcmore/ctf/dev/project/platform/my-nocobase/node_modules/sequelize/src/dialects/abstract/query-interface.js:1001:12)\n    at Proxy.findAll (/home/geekcmore/ctf/dev/project/platform/my-nocobase/node_modules/sequelize/src/model.js:1824:21)\n    at execute (/home/geekcmore/ctf/dev/project/platform/my-nocobase/packages/plugins/@nocobase/plugin-collection-sql/src/server/resources/sql.ts:52:20)\n    at middleware (/home/geekcmore/ctf/dev/project/platform/my-nocobase/packages/plugins/@nocobase/plugin-workflow-action-trigger/src/server/ActionTrigger.ts:53:5)"} module=sqlCollection submodule=execute method=error-handler app=main reqId=3bc7c670-351e-4ddd-a047-2d470d4200b8 dataSourceKey=main
2024-10-25 19:48:19 [error] response /api/sqlCollection:execute          method=POST path=/api/sqlCollection:execute res=[{"message":"SQLITE_ERROR: no such table: users"}] action={"actionName":"execute","resourceName":"sqlCollection","params":{"resourceName":"sqlCollection","actionName":"execute","values":{"sql":"select * from users"}}} userId=1 status=500 cost=6 app=main reqId=3bc7c670-351e-4ddd-a047-2d470d4200b8
2024-10-25 19:48:46 [info]  request POST /api/sqlCollection:execute      method=POST path=/api/sqlCollection:execute req={"header":{"x-role":"root","x-hostname":"localhost","x-timezone":"+08:00","x-locale":"zh-CN","x-authenticator":"basic"}} app=main reqId=7672c22a-c9b8-4815-9e98-0ac0b66b1961
2024-10-25 19:48:46 [debug] ctx permission                               meta={"can":{"role":"root","resource":"sqlCollection","action":"execute"},"resourceName":"sqlCollection","actionName":"execute","skip":true} module=sqlCollection submodule=execute app=main reqId=7672c22a-c9b8-4815-9e98-0ac0b66b1961 dataSourceKey=main
2024-10-25 19:48:46 [debug] acl params                                   module=sqlCollection submodule=execute app=main reqId=7672c22a-c9b8-4815-9e98-0ac0b66b1961 dataSourceKey=main
2024-10-25 19:48:46 [debug] acl parsedParams                             module=sqlCollection submodule=execute app=main reqId=7672c22a-c9b8-4815-9e98-0ac0b66b1961 dataSourceKey=main
2024-10-25 19:48:46 [error] SQLITE_ERROR: no such table: users           meta={"err":"Error\n    at Database.<anonymous> (/home/geekcmore/ctf/dev/project/platform/my-nocobase/node_modules/sequelize/src/dialects/sqlite/query.js:236:27)\n    at <anonymous> (/home/geekcmore/ctf/dev/project/platform/my-nocobase/node_modules/sequelize/src/dialects/sqlite/query.js:234:50)\n    at new Promise (<anonymous>)\n    at Query.run (/home/geekcmore/ctf/dev/project/platform/my-nocobase/node_modules/sequelize/src/dialects/sqlite/query.js:234:12)\n    at <anonymous> (/home/geekcmore/ctf/dev/project/platform/my-nocobase/node_modules/sequelize/src/sequelize.js:650:28)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at Proxy.select (/home/geekcmore/ctf/dev/project/platform/my-nocobase/node_modules/sequelize/src/dialects/abstract/query-interface.js:1001:12)\n    at Proxy.findAll (/home/geekcmore/ctf/dev/project/platform/my-nocobase/node_modules/sequelize/src/model.js:1824:21)\n    at execute (/home/geekcmore/ctf/dev/project/platform/my-nocobase/packages/plugins/@nocobase/plugin-collection-sql/src/server/resources/sql.ts:52:20)\n    at middleware (/home/geekcmore/ctf/dev/project/platform/my-nocobase/packages/plugins/@nocobase/plugin-workflow-action-trigger/src/server/ActionTrigger.ts:53:5)"} module=sqlCollection submodule=execute method=error-handler app=main reqId=7672c22a-c9b8-4815-9e98-0ac0b66b1961 dataSourceKey=main
2024-10-25 19:48:46 [error] response /api/sqlCollection:execute          method=POST path=/api/sqlCollection:execute res=[{"message":"SQLITE_ERROR: no such table: users"}] action={"actionName":"execute","resourceName":"sqlCollection","params":{"resourceName":"sqlCollection","actionName":"execute","values":{"sql":"select * from users"}}} userId=1 status=500 cost=29 app=main reqId=7672c22a-c9b8-4815-9e98-0ac0b66b1961

设置环境变量 DB_LOGGING=on, 看看实际执行的 SQL.

经测试 * v1.4.0-alpha.20241025082448 + mysql 8同样有该问题:

附sqlite下的数据库日志文件
sql_2024-10-25.zip (3.6 KB)

大概知道问题原因了,环境变量中设置了数据表前缀,这里就需要加上前缀。应该是开发的时候这个细节没被屏蔽,能否优化一下

SQL 语句是透传的。