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

Server DB Docker Image Feedback | 服务端 Database Docker 镜像问题反馈 #3391

Closed
arvinxx opened this issue Aug 3, 2024 · 122 comments
Closed

Comments

@arvinxx
Copy link
Contributor

arvinxx commented Aug 3, 2024

首先非常感谢 @cy948 的努力,完成了 Next Auth 和 LobeChat 现有 Database 系统的集成,使得我们可以构建起 LobeChat 的服务端数据库的 Docker 镜像。

服务端数据库的 docker 镜像已正式可用,镜像名为 lobehub/lobe-chat-database

关于服务端数据库的部署文档,详见: https://lobehub.com/docs/self-hosting/server-database

在此也列出一个简版的部署指南,供大家参考。如有其他问题,欢迎在下方留言。


  1. 创建 pg 实例,需要包含 pgvector 插件(注意:以下命令仅用于演示,因为这个 pg 实例并没有包含持久化部分,请自行构建一个符合你诉求的 生产级 pg 实例)
docker run --name my-postgres --network pg -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d pgvector/pgvector:pg16
  1. 创建一个 lobe-chat.env 文件用于存放环境变量:
#网站域名
APP_URL=http://localhost:3210

# DB 必须
KEY_VAULTS_SECRET=jgwsK28dspyVQoIf8/M3IIHl1h6LYYceSYNXeLpy6uk=
DATABASE_URL=postgres://postgres:mysecretpassword@my-postgres:5432/postgres


# NEXT_AUTH 相关,可以使用 auth0 等,如有其他接入诉求欢迎提 PR
NEXT_AUTH_SECRET=3904039cd41ea1bdf6c93db0db96e250
NEXT_AUTH_SSO_PROVIDERS=auth0
NEXTAUTH_URL=https://your-prod-domain.com/api/auth
AUTH0_CLIENT_ID=xxxxxx
AUTH0_CLIENT_SECRET=cSX_xxxxx
AUTH0_ISSUER=https://lobe-chat-demo.us.auth0.com

# S3 相关
S3_ACCESS_KEY_ID=xxxxxxxxxx
S3_SECRET_ACCESS_KEY=xxxxxxxxxx
S3_ENDPOINT=https://xxxxxxxxxx.r2.cloudflarestorage.com
S3_BUCKET=lobechat
NEXT_PUBLIC_S3_DOMAIN=https://s3-for-lobechat.your-domain.com
  1. 启动 lobe-chat-database docker 镜像
docker run -it -d -p 3210:3210 --network pg --env-file lobe-chat.env --name lobe-chat-database lobehub/lobe-chat-database

注意事项:确保数据库和 LobeChat DB 镜像在同一网络中

@lobehubbot
Copy link
Member

lobehubbot commented Aug 3, 2024

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


First of all, I am very grateful to @cy948 for his efforts in completing the integration of Next Auth and LobeChat’s existing Database system, allowing us to build LobeChat’s server image.

The docker image of the server database is now officially available. The image name is lobehub/lobe-chat-database.

The deployment guide is here: https://lobehub.com/docs/self-hosting/server-database

  1. Create a pg instance (Note: The following commands are for demonstration only, because this pg instance does not include the persistence part)
docker run --name my-postgres --network pg -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d pgvector/pgvector:pg16
  1. Create a lobe-chat.env file to store environment variables:
# DB required
KEY_VAULTS_SECRET=jgwsK28dspyVQoIf8/M3IIHl1h6LYYceSYNXeLpy6uk=
DATABASE_URL=postgres://postgres:mysecretpassword@my-postgres:5432/postgres

# NEXT_AUTH related
NEXT_AUTH_SECRET=3904039cd41ea1bdf6c93db0db96e250
NEXT_AUTH_SSO_PROVIDERS=auth0
NEXTAUTH_URL=https://your-prod-domain.com/api/auth
AUTH0_CLIENT_ID=xxxxxx
AUTH0_CLIENT_SECRET=cSX_xxxxx
AUTH0_ISSUER=https://lobe-chat-demo.us.auth0.com

# S3 related
S3_ACCESS_KEY_ID=xxxxxxxxxx
S3_SECRET_ACCESS_KEY=xxxxxxxxxx
S3_ENDPOINT=https://xxxxxxxxxx.r2.cloudflarestorage.com
S3_BUCKET=lobechat
NEXT_PUBLIC_S3_DOMAIN=https://s3-for-lobechat.your-domain.com
  1. Start the lobe-chat-database docker image
docker run -it -d -p 3210:3210 --network pg --env-file lobe-chat.env --name lobe-chat-database lobehub/lobe-chat-database

@lobehub lobehub deleted a comment from lobehubbot Aug 3, 2024
@arvinxx arvinxx pinned this issue Aug 3, 2024
@Matinal111

This comment was marked as resolved.

@arvinxx

This comment was marked as resolved.

@lobehubbot

This comment was marked as resolved.

@Matinal111

This comment was marked as resolved.

@lobehubbot

This comment was marked as resolved.

@arvinxx

This comment was marked as resolved.

@lobehubbot

This comment was marked as resolved.

@iparanoid

This comment was marked as outdated.

@lobehubbot

This comment was marked as outdated.

@sqkkyzx
Copy link

sqkkyzx commented Aug 4, 2024

使用 Authing 身份认证提供者的配置方法

Authing 可以兼容 Auth0,但是是国内的服务,所以可以用微博、微信、QQ登录。

  1. 注册 Authing ,新建一个 ToE 或者 ToC 用户池。
  2. 身份源管理页面增加社会化身份源
  3. 应用-自建应用中,新建一个应用,此时可以看到如下图所示内容,你需要设置和保存认证配置,并根据生成的端点信息来配置 lobehub 的环境变量。
1722774948509
  1. 配置要点:
  • NEXT_AUTH_SSO_PROVIDERS 应设置为 auth0
  • NEXTAUTH_URLAuthing认证配置中的登录回调URL并不是相同的。 NEXTAUTH_URL 应配置为 https://{your-prod-domin}/api/auth ,而登录回调URL应配置为 https://{your-prod-domin}/api/auth/callback/auth0
  • AUTH0_ISSUER 应设置为端点信息中的Issuer,不要删除结尾的/oidc

@arvinxx

This comment was marked as resolved.

@lobehubbot

This comment was marked as resolved.

@darkelfzdy

This comment was marked as resolved.

@arvinxx
Copy link
Contributor Author

arvinxx commented Aug 5, 2024

@sqkkyzx 欢迎将其提交为文档,帮助更多 LobeChat 用户

@lobehubbot

This comment was marked as resolved.

@zhangleijun111

This comment was marked as outdated.

@lobehubbot

This comment was marked as outdated.

@darkelfzdy

This comment was marked as resolved.

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I saw that the document has been updated Using server-side database deployment, which mentions the two variables NEXT_PUBLIC_SERVICE_MODE and DATABASE_DRIVER.
If I use vercel+local Postgres mode, the above two variables should be set as follows:
NEXT_PUBLIC_SERVICE_MODE=client
DATABASE_DRIVER=node

@arvinxx
Copy link
Contributor Author

arvinxx commented Aug 6, 2024

@darkelfzdy 需要,你得设置为:

NEXT_PUBLIC_SERVICE_MODE=server
DATABASE_DRIVER=node

但我不太建议使用 vercel + node PG 的模式,大概率会存在通信延迟的问题,导致响应比较慢。如果在同一处的话,可以做到百毫秒的响应,但如果分开来的话,估计得到秒级了

@lobehubbot

This comment was marked as resolved.

@darkelfzdy

This comment was marked as resolved.

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@darkelfzdy required, you have to set it to:

NEXT_PUBLIC_SERVICE_MODE=server
DATABASE_DRIVER=node

But I don’t recommend using the vercel + node PG mode. There is a high probability that there will be communication delay problems, resulting in slower response. If they are in the same place, they can achieve a response of hundreds of milliseconds, but if they are separated, it is estimated to be on the second level.

Indeed, I am also a little worried. If it is Vercel + Serverless Postgres model, Vercel's Postgres free time seems to be only 60 hours a month, which is obviously not enough. The best way seems to be Docker image + Node Postgres, all local

@arvinxx

This comment was marked as resolved.

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@darkelfzdy Serverless PG instance, it is recommended to use neon, this combination is better

@darkelfzdy

This comment was marked as resolved.

@morningtzh
Copy link

image
/ $ node /app/docker.cjs
[Database] Start to migration...
❌ Database migrate failed. Please check your database is valid and DATABASE_URL is set correctly. The error detail is below:
error: column "client_id" of relation "messages" already exists
    at /app/node_modules/.pnpm/[email protected]/node_modules/pg/lib/client.js:526:17
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /app/node_modules/drizzle-orm/pg-core/dialect.cjs:60:13
    at async NodePgSession.transaction (/app/node_modules/drizzle-orm/node-postgres/session.cjs:141:22)
    at async PgDialect.migrate (/app/node_modules/drizzle-orm/pg-core/dialect.cjs:56:5)
    at async Object.migrate (/app/node_modules/drizzle-orm/node-postgres/migrator.cjs:27:3)
    at async runMigrations (/app/docker.cjs:16:3) {
  length: 136,
  severity: 'ERROR',
  code: '42701',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'tablecmds.c',
  line: '7134',
  routine: 'check_for_column_name_collision'
}

之前一直使用 Dockerfile 构建的镜像,传入了clark参数用于登录。今天保留原有构建环境变量(clark / s3 / db),尝试使用 Dockerfile.database 构建镜像,发现起不了。bash进入镜像后,export DATABASE_URL 再运行 node /app/docker.cjs,发现有数据库字段冲突的问题,不太清楚是什么原因导致的冲突。

也看了上面自己建表的问题,我这个是早期通过 db:push 建立的。

麻烦帮忙看一下是否需要重新建立数据库,另外 Dockerfile.database 镜像是否还兼容构建时传入clark参数用于登录。

@arvinxx
Copy link
Contributor Author

arvinxx commented Aug 12, 2024

发现有数据库字段冲突的问题,不太清楚是什么原因导致的冲突。

@morningtzh 可以看下这段迁移 sql ,https://github.com/lobehub/lobe-chat/blob/main/src/database/server/migrations/0001_add_client_id.sql

这里的步骤是都会执行一遍的,如果你是用的db:push ,那么数据库里已经有 client_id 了,这里自然会冲突。

解决方案有两种:

  1. 如果是完全从头自己建镜像,那么可以直接注释这一个文件中的所有 sql ,这样迁移脚本虽然会执行这个 sql 文件,但是由于里面是空的,所以会认为执行成功,这样就能进到下一个 sql 迁移脚本。如果还报错就继续用类似方法,直到全部执行完毕。
  2. 删掉数据库重新部署一遍,这样应该不需要做什么操作直接就可以初始化完毕。

Dockerfile.database 镜像是否还兼容构建时传入clark参数用于登录

理论上应该是还支持的。你可以试下。

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Found a database field conflict problem, not sure what caused the conflict.

@morningtzh You can take a look at this migration sql, https://github.com/lobehub/lobe-chat/blob/main/src/database/server/migrations/0001_add_client_id.sql

The steps here are all executed once. If you use db:push, then there is already client_id in the database, and there will naturally be a conflict here.

There are two solutions:

  1. If you build the image completely from scratch, you can directly comment all the sql in this file. In this way, although the migration script will execute the sql file, it will be considered successful because it is empty, so you can enter Next sql migration script. If an error is still reported, continue using similar methods until all executions are completed.
  2. Delete the database and redeploy it, so that the initialization can be completed without any operations.

Is the Dockerfile.database image still compatible with the clark parameter passed in when building for login?

Theoretically it should be supported. You can try it.

@morningtzh
Copy link

发现有数据库字段冲突的问题,不太清楚是什么原因导致的冲突。

@morningtzh 可以看下这段迁移 sql ,https://github.com/lobehub/lobe-chat/blob/main/src/database/server/migrations/0001_add_client_id.sql

这里的步骤是都会执行一遍的,如果你是用的db:push ,那么数据库里已经有 client_id 了,这里自然会冲突。

解决方案有两种:

  1. 如果是完全从头自己建镜像,那么可以直接注释这一个文件中的所有 sql ,这样迁移脚本虽然会执行这个 sql 文件,但是由于里面是空的,所以会认为执行成功,这样就能进到下一个 sql 迁移脚本。如果还报错就继续用类似方法,直到全部执行完毕。
  2. 删掉数据库重新部署一遍,这样应该不需要做什么操作直接就可以初始化完毕。

Dockerfile.database 镜像是否还兼容构建时传入clark参数用于登录

理论上应该是还支持的。你可以试下。

谢谢 确实可以,我把0001和0002都注释掉了,运行时环境变量补全S3和DB的就能使用,auth0并不是强制依赖的,clerk也能结合新的 Dockerfile.database 镜像运行。

使用手机登录(电脑也在线),切换助手后端会报错 session not found,偶尔前端会报一下,但不影响使用。接下来持续观察一下~

2024-08-14T15:09:36.977934650Z {"level":30,"time":1723648176977,"pid":1,"hostname":"lobe-chat--7tv2x58-7d46986c4f-6zxk9","msg":"Error in tRPC handler (lambda) on path: session.getSessionConfig, type: query"}
2024-08-14T15:09:36.978873296Z Error: Session not found
2024-08-14T15:09:36.978898995Z     at /app/.next/server/app/trpc/lambda/[trpc]/route.js:4:22323
2024-08-14T15:09:36.978909034Z     ... 8 lines matching cause stack trace ...
2024-08-14T15:09:36.978917249Z     at async Promise.all (index 1) {
2024-08-14T15:09:36.978925515Z   code: 'INTERNAL_SERVER_ERROR',
2024-08-14T15:09:36.978934953Z   name: 'TRPCError',
2024-08-14T15:09:36.978943358Z   [cause]: Error: Session not found
2024-08-14T15:09:36.978951373Z       at /app/.next/server/app/trpc/lambda/[trpc]/route.js:4:22323
2024-08-14T15:09:36.978960430Z       at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2024-08-14T15:09:36.978968566Z       at async E.f.middlewares (/app/.next/server/chunks/54430.js:1:1900)
2024-08-14T15:09:36.978978424Z       at async t (/app/.next/server/chunks/54430.js:1:2174)
2024-08-14T15:09:36.978986429Z       at async t (/app/.next/server/chunks/54430.js:1:2174)
2024-08-14T15:09:36.978994554Z       at async t (/app/.next/server/chunks/54430.js:1:2174)
2024-08-14T15:09:36.979002319Z       at async t (/app/.next/server/chunks/54430.js:1:2174)
2024-08-14T15:09:36.979009853Z       at async r (/app/.next/server/chunks/54430.js:1:2513)
2024-08-14T15:09:36.979017548Z       at async /app/.next/server/chunks/50893.js:1:7091
2024-08-14T15:09:36.979025503Z       at async Promise.all (index 1)
2024-08-14T15:09:36.979033047Z }

@arvinxx
Copy link
Contributor Author

arvinxx commented Aug 14, 2024

@morningtzh 手机端的 session 的问题应该在 #3428 这里会修复

@morningtzh
Copy link

@morningtzh 手机端的 session 的问题应该在 #3428 这里会修复

好的 👌,原来是已知问题。

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@morningtzh The session problem on the mobile phone should be fixed in #3428

Ok 👌, it turns out to be a known issue.

@coulsontl
Copy link
Contributor

@coulsontl 不要自己建表,否则出错了自己解决,帮不了你。默认的 db 镜像里会自动创建表结构和自动完成数据库迁移的。如果不行建议检查你的db url写的对不对,不行就删掉 db 重来。

如果你是数据库专家当我没说,自己看下 src/database/server/migration 里的sql ,自行执行表结构迁移应该也可以的。

@arvinxx 抱歉是我没表达清楚,我并没有建表只是新建了数据库;数据库镜像和文件我删了重装很多次都是报错 error: relation "nextauth_accounts" does not exist;想问一下自动建表的过程是在什么时候,能否多打印一些日志方便排查问题,现在启动日志里没有日志。URL: 链接没看出啥问题 postgres://root:[email protected]:5432/lobechat, 而且我从pg镜像的日志看是正常连接的,可以看到select然后报错的日志,但没有新建表的日志

▲ Next.js 14.2.5
  - Local:        http://localhost:3210
  - Network:      http://0.0.0.0:3210

 ✓ Starting...
 ✓ Ready in 177ms
[auth][error] AdapterError: Read more at https://errors.authjs.dev#adaptererror
[auth][cause]: error: relation "nextauth_accounts" does not exist
    at /app/node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js:45:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /app/.next/server/chunks/76514.js:27:8152
    at async getUserByAccount (/app/.next/server/app/api/auth/[...nextauth]/route.js:1:3596)
    at async r.<computed> (/app/.next/server/chunks/7247.js:6:41304)
    at async ir (/app/.next/server/chunks/7247.js:362:34258)
    at async ip (/app/.next/server/chunks/7247.js:362:45365)
    at async im (/app/.next/server/chunks/7247.js:362:49738)
    at async /app/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:36258
    at async eR.execute (/app/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:26874)
[auth][details]: {}
[auth][error] AdapterError: Read more at https://errors.authjs.dev#adaptererror
[auth][cause]: error: relation "nextauth_accounts" does not exist
    at /app/node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js:45:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /app/.next/server/chunks/76514.js:27:8152
    at async getUserByAccount (/app/.next/server/app/api/auth/[...nextauth]/route.js:1:3596)
    at async r.<computed> (/app/.next/server/chunks/7247.js:6:41304)
    at async ir (/app/.next/server/chunks/7247.js:362:34258)
    at async ip (/app/.next/server/chunks/7247.js:362:45365)
    at async im (/app/.next/server/chunks/7247.js:362:49738)
    at async /app/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:36258
    at async eR.execute (/app/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:26874)
[auth][details]: {}
[NextAuth] Error: {
  cause: 'Configuration',
  message: 'Wrong configuration, make sure you have the correct environment variables set. Visit https://lobehub.com/docs/self-hosting/advanced/authentication for more details.',
  name: 'NextAuth Error'
}

pg镜像的日志


PostgreSQL Database directory appears to contain a database; Skipping initialization

2024-08-15 01:02:56.690 UTC [1] LOG:  starting PostgreSQL 16.4 (Debian 16.4-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2024-08-15 01:02:56.690 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2024-08-15 01:02:56.691 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2024-08-15 01:02:56.693 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2024-08-15 01:02:56.698 UTC [29] LOG:  database system was shut down at 2024-08-15 01:02:55 UTC
2024-08-15 01:02:56.705 UTC [1] LOG:  database system is ready to accept connections
2024-08-15 01:03:28.813 UTC [34] ERROR:  relation "nextauth_accounts" does not exist at character 679
2024-08-15 01:03:28.813 UTC [34] STATEMENT:  select "nextauth_accounts"."access_token", "nextauth_accounts"."expires_at", "nextauth_accounts"."id_token", "nextauth_accounts"."provider", "nextauth_accounts"."providerAccountId", "nextauth_accounts"."refresh_token", "nextauth_accounts"."scope", "nextauth_accounts"."session_state", "nextauth_accounts"."token_type", "nextauth_accounts"."type", "nextauth_accounts"."userId", "users"."id", "users"."username", "users"."email", "users"."avatar", "users"."phone", "users"."first_name", "users"."last_name", "users"."full_name", "users"."is_onboarded", "users"."clerk_created_at", "users"."email_verified_at", "users"."preference", "users"."created_at", "users"."updated_at" from "nextauth_accounts" inner join "users" on "nextauth_accounts"."userId" = "users"."id" where ("nextauth_accounts"."provider" = $1 and "nextauth_accounts"."providerAccountId" = $2)
2024-08-15 01:05:36.650 UTC [39] ERROR:  relation "nextauth_accounts" does not exist at character 679
2024-08-15 01:05:36.650 UTC [39] STATEMENT:  select "nextauth_accounts"."access_token", "nextauth_accounts"."expires_at", "nextauth_accounts"."id_token", "nextauth_accounts"."provider", "nextauth_accounts"."providerAccountId", "nextauth_accounts"."refresh_token", "nextauth_accounts"."scope", "nextauth_accounts"."session_state", "nextauth_accounts"."token_type", "nextauth_accounts"."type", "nextauth_accounts"."userId", "users"."id", "users"."username", "users"."email", "users"."avatar", "users"."phone", "users"."first_name", "users"."last_name", "users"."full_name", "users"."is_onboarded", "users"."clerk_created_at", "users"."email_verified_at", "users"."preference", "users"."created_at", "users"."updated_at" from "nextauth_accounts" inner join "users" on "nextauth_accounts"."userId" = "users"."id" where ("nextauth_accounts"."provider" = $1 and "nextauth_accounts"."providerAccountId" = $2)
2024-08-15 01:07:56.781 UTC [27] LOG:  checkpoint starting: time
2024-08-15 01:08:00.903 UTC [27] LOG:  checkpoint complete: wrote 44 buffers (0.3%); 0 WAL file(s) added, 0 removed, 0 recycled; write=4.111 s, sync=0.008 s, total=4.123 s; sync files=11, longest=0.007 s, average=0.001 s; distance=260 kB, estimate=260 kB; lsn=0/152B6E0, redo lsn=0/152B6A8
2024-08-16 13:33:29.365 UTC [27] LOG:  checkpoint starting: time
2024-08-16 13:33:38.433 UTC [4413] ERROR:  relation "nextauth_accounts" does not exist at character 679
2024-08-16 13:33:38.433 UTC [4413] STATEMENT:  select "nextauth_accounts"."access_token", "nextauth_accounts"."expires_at", "nextauth_accounts"."id_token", "nextauth_accounts"."provider", "nextauth_accounts"."providerAccountId", "nextauth_accounts"."refresh_token", "nextauth_accounts"."scope", "nextauth_accounts"."session_state", "nextauth_accounts"."token_type", "nextauth_accounts"."type", "nextauth_accounts"."userId", "users"."id", "users"."username", "users"."email", "users"."avatar", "users"."phone", "users"."first_name", "users"."last_name", "users"."full_name", "users"."is_onboarded", "users"."clerk_created_at", "users"."email_verified_at", "users"."preference", "users"."created_at", "users"."updated_at" from "nextauth_accounts" inner join "users" on "nextauth_accounts"."userId" = "users"."id" where ("nextauth_accounts"."provider" = $1 and "nextauth_accounts"."providerAccountId" = $2)
2024-08-16 13:35:03.247 UTC [27] LOG:  checkpoint complete: wrote 938 buffers (5.7%); 0 WAL file(s) added, 0 removed, 0 recycled; write=93.840 s, sync=0.012 s, total=93.882 s; sync files=308, longest=0.002 s, average=0.001 s; distance=4269 kB, estimate=4269 kB; lsn=0/1956D40, redo lsn=0/1956D08

@navono
Copy link

navono commented Aug 17, 2024

参考下这篇:https://alwq.xyz/post/2024-08-07-lobechat-database-deploy/
我在 NAS 通过 docker 部署,CF 做转发。

version: '3.8'

services:
  lobe-chat:
    image: lobehub/lobe-chat-database
    container_name: lobe-chat
    restart: always
    tty: true
    ports:
      - '3210:3210'
    env_file:
      - /share/data/lobechat/lobechat.env
    networks:
      - pg
    depends_on:
      - pg
      
  pg:
    image: postgres:latest
    restart: always
    tty: true
    env_file:
      - /share/data/lobechat/lobechat.env
    ports:
      - 5432:5432
    networks:
      - pg
    environment:
      PGUSER: ${PGUSER:-postgres}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-lobechat666}
      POSTGRES_DB: ${POSTGRES_DB:-lobechat}
      PGDATA: ${PGDATA:-/var/lib/postgresql/data/pgdata}
    volumes:
      - /share/data/lobechat/db/data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD", "pg_isready"]
      interval: 1s
      timeout: 3s
      retries: 30

networks:
  pg:
    driver: bridge

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Refer to this article: https://alwq.xyz/post/2024-08-07-lobechat-database-deploy/
I deploy via docker on NAS, and use CF for forwarding.

@darkelfzdy

This comment was marked as resolved.

@lobehubbot

This comment was marked as resolved.

@arvinxx

This comment was marked as resolved.

@lobehubbot

This comment was marked as resolved.

@CHENXCHEN
Copy link

CHENXCHEN commented Aug 18, 2024

服务器版本不支持 clerk,在 env 文件里配置了 NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
浏览器打开依然报错:
Error: @clerk/nextjs: Missing publishableKey. You can get your key at https://dashboard.clerk.com/last-active?path=api-keys.

@arvinxx
Copy link
Contributor Author

arvinxx commented Aug 18, 2024

@CHENXCHEN database 官方 docker 镜像不支持 clerk,请使用 auth0。如果要使用 clerk,请采用以下两种方式:

  1. 自行构建 docker 镜像;
  2. 使用 vercel/Railway 等平台部署

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@CHENXCHEN database official docker image does not support clerk, please use auth0. If you want to use clerk, please use the following two methods:

  1. Build docker image by yourself;
  2. Deploy using platforms such as vercel/Railway

@wcu1117
Copy link

wcu1117 commented Aug 21, 2024

@coulsontl 不要自己建表,否则出错了自己解决,帮不了你。默认的 db 镜像里会自动创建表结构和自动完成数据库迁移的。如果不行建议检查你的db url写的对不对,不行就删掉 db 重来。
如果你是数据库专家当我没说,自己看下 src/database/server/migration 里的sql ,自行执行表结构迁移应该也可以的。

@arvinxx 抱歉是我没表达清楚,我并没有建表只是新建了数据库;数据库镜像和文件我删了重装很多次都是报错 error: relation "nextauth_accounts" does not exist;想问一下自动建表的过程是在什么时候,能否多打印一些日志方便排查问题,现在启动日志里没有日志。URL: 链接没看出啥问题 postgres://root:[email protected]:5432/lobechat, 而且我从pg镜像的日志看是正常连接的,可以看到select然后报错的日志,但没有新建表的日志

▲ Next.js 14.2.5
  - Local:        http://localhost:3210
  - Network:      http://0.0.0.0:3210

 ✓ Starting...
 ✓ Ready in 177ms
[auth][error] AdapterError: Read more at https://errors.authjs.dev#adaptererror
[auth][cause]: error: relation "nextauth_accounts" does not exist
    at /app/node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js:45:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /app/.next/server/chunks/76514.js:27:8152
    at async getUserByAccount (/app/.next/server/app/api/auth/[...nextauth]/route.js:1:3596)
    at async r.<computed> (/app/.next/server/chunks/7247.js:6:41304)
    at async ir (/app/.next/server/chunks/7247.js:362:34258)
    at async ip (/app/.next/server/chunks/7247.js:362:45365)
    at async im (/app/.next/server/chunks/7247.js:362:49738)
    at async /app/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:36258
    at async eR.execute (/app/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:26874)
[auth][details]: {}
[auth][error] AdapterError: Read more at https://errors.authjs.dev#adaptererror
[auth][cause]: error: relation "nextauth_accounts" does not exist
    at /app/node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js:45:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /app/.next/server/chunks/76514.js:27:8152
    at async getUserByAccount (/app/.next/server/app/api/auth/[...nextauth]/route.js:1:3596)
    at async r.<computed> (/app/.next/server/chunks/7247.js:6:41304)
    at async ir (/app/.next/server/chunks/7247.js:362:34258)
    at async ip (/app/.next/server/chunks/7247.js:362:45365)
    at async im (/app/.next/server/chunks/7247.js:362:49738)
    at async /app/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:36258
    at async eR.execute (/app/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:26874)
[auth][details]: {}
[NextAuth] Error: {
  cause: 'Configuration',
  message: 'Wrong configuration, make sure you have the correct environment variables set. Visit https://lobehub.com/docs/self-hosting/advanced/authentication for more details.',
  name: 'NextAuth Error'
}

pg镜像的日志


PostgreSQL Database directory appears to contain a database; Skipping initialization

2024-08-15 01:02:56.690 UTC [1] LOG:  starting PostgreSQL 16.4 (Debian 16.4-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2024-08-15 01:02:56.690 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2024-08-15 01:02:56.691 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2024-08-15 01:02:56.693 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2024-08-15 01:02:56.698 UTC [29] LOG:  database system was shut down at 2024-08-15 01:02:55 UTC
2024-08-15 01:02:56.705 UTC [1] LOG:  database system is ready to accept connections
2024-08-15 01:03:28.813 UTC [34] ERROR:  relation "nextauth_accounts" does not exist at character 679
2024-08-15 01:03:28.813 UTC [34] STATEMENT:  select "nextauth_accounts"."access_token", "nextauth_accounts"."expires_at", "nextauth_accounts"."id_token", "nextauth_accounts"."provider", "nextauth_accounts"."providerAccountId", "nextauth_accounts"."refresh_token", "nextauth_accounts"."scope", "nextauth_accounts"."session_state", "nextauth_accounts"."token_type", "nextauth_accounts"."type", "nextauth_accounts"."userId", "users"."id", "users"."username", "users"."email", "users"."avatar", "users"."phone", "users"."first_name", "users"."last_name", "users"."full_name", "users"."is_onboarded", "users"."clerk_created_at", "users"."email_verified_at", "users"."preference", "users"."created_at", "users"."updated_at" from "nextauth_accounts" inner join "users" on "nextauth_accounts"."userId" = "users"."id" where ("nextauth_accounts"."provider" = $1 and "nextauth_accounts"."providerAccountId" = $2)
2024-08-15 01:05:36.650 UTC [39] ERROR:  relation "nextauth_accounts" does not exist at character 679
2024-08-15 01:05:36.650 UTC [39] STATEMENT:  select "nextauth_accounts"."access_token", "nextauth_accounts"."expires_at", "nextauth_accounts"."id_token", "nextauth_accounts"."provider", "nextauth_accounts"."providerAccountId", "nextauth_accounts"."refresh_token", "nextauth_accounts"."scope", "nextauth_accounts"."session_state", "nextauth_accounts"."token_type", "nextauth_accounts"."type", "nextauth_accounts"."userId", "users"."id", "users"."username", "users"."email", "users"."avatar", "users"."phone", "users"."first_name", "users"."last_name", "users"."full_name", "users"."is_onboarded", "users"."clerk_created_at", "users"."email_verified_at", "users"."preference", "users"."created_at", "users"."updated_at" from "nextauth_accounts" inner join "users" on "nextauth_accounts"."userId" = "users"."id" where ("nextauth_accounts"."provider" = $1 and "nextauth_accounts"."providerAccountId" = $2)
2024-08-15 01:07:56.781 UTC [27] LOG:  checkpoint starting: time
2024-08-15 01:08:00.903 UTC [27] LOG:  checkpoint complete: wrote 44 buffers (0.3%); 0 WAL file(s) added, 0 removed, 0 recycled; write=4.111 s, sync=0.008 s, total=4.123 s; sync files=11, longest=0.007 s, average=0.001 s; distance=260 kB, estimate=260 kB; lsn=0/152B6E0, redo lsn=0/152B6A8
2024-08-16 13:33:29.365 UTC [27] LOG:  checkpoint starting: time
2024-08-16 13:33:38.433 UTC [4413] ERROR:  relation "nextauth_accounts" does not exist at character 679
2024-08-16 13:33:38.433 UTC [4413] STATEMENT:  select "nextauth_accounts"."access_token", "nextauth_accounts"."expires_at", "nextauth_accounts"."id_token", "nextauth_accounts"."provider", "nextauth_accounts"."providerAccountId", "nextauth_accounts"."refresh_token", "nextauth_accounts"."scope", "nextauth_accounts"."session_state", "nextauth_accounts"."token_type", "nextauth_accounts"."type", "nextauth_accounts"."userId", "users"."id", "users"."username", "users"."email", "users"."avatar", "users"."phone", "users"."first_name", "users"."last_name", "users"."full_name", "users"."is_onboarded", "users"."clerk_created_at", "users"."email_verified_at", "users"."preference", "users"."created_at", "users"."updated_at" from "nextauth_accounts" inner join "users" on "nextauth_accounts"."userId" = "users"."id" where ("nextauth_accounts"."provider" = $1 and "nextauth_accounts"."providerAccountId" = $2)
2024-08-16 13:35:03.247 UTC [27] LOG:  checkpoint complete: wrote 938 buffers (5.7%); 0 WAL file(s) added, 0 removed, 0 recycled; write=93.840 s, sync=0.012 s, total=93.882 s; sync files=308, longest=0.002 s, average=0.001 s; distance=4269 kB, estimate=4269 kB; lsn=0/1956D40, redo lsn=0/1956D08

请问你这个解决了吗,我是直接本地建了一个数据库,没有用docker之类的,连接上去也不会自动建表啥的,在auth.ts设置好了adapter 就报错:adapter_getSessionAndUser { args: [ 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwia2lkIjoiR19mSndsMGRsVkRsVmpMVTYwVFdPWEQ0dGM2Ukpib3pFWVBhcW5TYloxOV9nR1ROS0lUb293Qlh1MWNsWkxNVm5qcThWdkh5OHRFdGJUQ09rZHA1Y0EifQ..oP8geLN7l2b_LxMDZedJ4Q.3wII3NXMDx1u-KPqdajF8HqkT5srrJLu62EPRuLsMO-kLCts9BfPbKWMciw76-eWyKJCfByWi2IxgMZmW8YRka1B9rJXX6MVs-mglw0Geni6 a-kIr1ifoSsUN2BqBXL6SwEP51Iw1AjozqS-BBMSbWIbV7WSPheVNLb2hf3jidxvehFxuj8yKeVvj6uJA2IBm_trmVfwODPzjb8Pl-USPhO4AASozd8fUSZ16i1lW28BpNdfc7kRTJbQxSsa_-hVy_N38vQHwn_Pw6pMTqZHkuiUWu62XRGxsReJAJAGT00xbgDnAQw1ZfQqWWnMTnsb8zUYwmo6Vu0-tLhH-SqqCwVG6H3ciqNnwm4QXdSvG1aGIMhN0fvJyU0lhOu1-BSw2xTik_lPIB9JsdCCEzncgiFNM-7U02PlL-sRUWtvy8k2yKHEL7FzTdfMwC13KvatZkUkQamZ0gDdMJtaFRebhYnXRRKjZ8HrhqNnwwxFtLU.VqLn2o1KBx1Iy1z0a7oOmwgyVbl9eMnEw7DBn_RkFto' ] } AdapterError: Read more at https://errors.authjs.dev#adaptererror

@Lonvih
Copy link

Lonvih commented Aug 22, 2024

ACCESS_CODE 没有任何作用, 这是预期的结果吗
lobe-chat.env:

KEY_VAULTS_SECRET=*****
DATABASE_URL=postgres://postgres:***@my-postgres:***/postgres

# NEXT_AUTH related
NEXT_AUTH_SECRET=1ea8*****************09a
NEXT_AUTH_SSO_PROVIDERS=github
GITHUB_CLIENT_ID=Iv***********l
GITHUB_CLIENT_SECRET=6********************c
ACCESS_CODE=m**********
NEXTAUTH_URL=https://lobe.****.com/api/auth

登录后不需要 ACCESS_CODE 也可以生效

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


ACCESS_CODE has no effect, is this the expected result?
lobe-chat.env:

KEY_VAULTS_SECRET=*****
DATABASE_URL=postgres://postgres:***@my-postgres:***/postgres

# NEXT_AUTH related
NEXT_AUTH_SECRET=1ea8************************09a
NEXT_AUTH_SSO_PROVIDERS=github
GITHUB_CLIENT_ID=Iv************l
GITHUB_CLIENT_SECRET=6********************c
ACCESS_CODE=m************
NEXTAUTH_URL=https://lobe.****.com/api/auth

It can take effect without ACCESS_CODE after logging in.

@zhangleijun111
Copy link

zhangleijun111 commented Aug 22, 2024 via email

@Lonvih
Copy link

Lonvih commented Aug 22, 2024

嗯这段是教程里面的是否删除就好了? 发自我的iPhone

------------------ 原始邮件 ------------------ 发件人: Rory @.> 发送时间: 2024年8月22日 12:07 收件人: lobehub/lobe-chat @.> 抄送: zhangleijun111 @.>, Comment @.> 主题: Re: [lobehub/lobe-chat] Server DB Docker Image Feedback | 服务端 Database Docker 镜像问题反馈 (Issue #3391) ACCESS_CODE 没有任何作用, 这是预期的结果吗 lobe-chat.env: KEY_VAULTS_SECRET=***** @.:/postgres # NEXT_AUTH related NEXT_AUTH_SECRET=1ea809a NEXT_AUTH_SSO_PROVIDERS=github GITHUB_CLIENT_ID=Ivl GITHUB_CLIENT_SECRET=6***********c ACCESS_CODE=m********** NEXTAUTH_URL=https://lobe.****.com/api/auth 登录后不需要 ACCESS_CODE 也可以生效 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.>

image
文档中写的是 required , 是否有可以添加密码校验的方法, 如果使用 lobe-chat-database 的话

@arvinxx
Copy link
Contributor Author

arvinxx commented Aug 22, 2024

嗯这段是教程里面的是否删除就好了? 发自我的iPhone

------------------ 原始邮件 ------------------ 发件人: Rory @.> 发送时间: 2024年8月22日 12:07 收件人: lobehub/lobe-chat _@**._> 抄送: zhangleijun111 _@.>, Comment @._> 主题: Re: [lobehub/lobe-chat] Server DB Docker Image Feedback | 服务端 Database Docker 镜像问题反馈 (Issue #3391) ACCESS_CODE 没有任何作用, 这是预期的结果吗 lobe-chat.env: KEY_VAULTS_SECRET=*** @.:/postgres # NEXT_AUTH related NEXT_AUTH_SECRET=1ea8**09a NEXT_AUTH_SSO_PROVIDERS=github GITHUB_CLIENT_ID=Ivl GITHUB_CLIENT_SECRET=6*************c ACCESS_CODE=m******** NEXTAUTH_URL=https://lobe.****.com/api/auth 登录后不需要 ACCESS_CODE 也可以生效 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.**>

image 文档中写的是 required , 是否有可以添加密码校验的方法, 如果使用 lobe-chat-database 的话

用 DB 的话就不应该再用密码了,都按用户实例做隔离了。

@arvinxx
Copy link
Contributor Author

arvinxx commented Aug 22, 2024

经过三周左右的反馈,lobechat-database 的大部分自部署问题已经解决,此贴完结。如果有其余自部署问题,请继续在 #3527 下反馈。

@arvinxx arvinxx closed this as completed Aug 22, 2024
@lobehubbot
Copy link
Member

@arvinxx

This issue is closed, If you have any questions, you can comment and reply.
此问题已经关闭。如果您有任何问题,可以留言并回复。

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


After about three weeks of feedback, most of the self-deployment issues of lobechat-database have been resolved, and this post is complete. If you have any other self-deployment issues, please continue to report them under #3527.

@lobehub lobehub locked as resolved and limited conversation to collaborators Aug 22, 2024
@arvinxx arvinxx unpinned this issue Aug 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests