[GH-ISSUE #5707] Migration from v2.6.7 to v3.4.2: is it safe to reuse existing x-ui.db? #3971

Closed
opened 2026-10-31 20:36:15 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @cyb3ralbert on GitHub (Jul 1, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5707

Question

We are running 3x-ui v2.6.7 in Docker and want to upgrade to v3.4.2.

Our setup:

  • Docker deployment
  • x-ui.db mounted as volume: ./db/:/etc/x-ui/
  • VLESS + Reality inbound with ~36 clients
  • MongoDB-based Telegram bot connected to the panel API

Is it safe to simply change the image tag from v2.6.7 to v3.4.2 and reuse the existing x-ui.db?

Specifically:

  1. Did the database schema change between v2.6.7 and v3.4.2? Will 3x-ui auto-migrate it?
  2. Are there any known breaking changes in the API endpoints between these versions?
  3. Any known issues with Reality inbounds after upgrade?

Thank you.

Originally created by @cyb3ralbert on GitHub (Jul 1, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5707 ## Question We are running 3x-ui v2.6.7 in Docker and want to upgrade to v3.4.2. Our setup: - Docker deployment - x-ui.db mounted as volume: `./db/:/etc/x-ui/` - VLESS + Reality inbound with ~36 clients - MongoDB-based Telegram bot connected to the panel API **Is it safe to simply change the image tag from `v2.6.7` to `v3.4.2` and reuse the existing `x-ui.db`?** Specifically: 1. Did the database schema change between v2.6.7 and v3.4.2? Will 3x-ui auto-migrate it? 2. Are there any known breaking changes in the API endpoints between these versions? 3. Any known issues with Reality inbounds after upgrade? Thank you.
bsakaguchi 2026-10-31 20:36:15 +07:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jul 1, 2026):

Short answer: yes, you can point v3.4.2 at your existing x-ui.db — the schema migration is automatic. The part that will actually break is your custom Telegram bot's calls to the panel REST API, for two separate reasons detailed below.

1. Database schema — auto-migrated, no manual step needed

database.InitDB (internal/database/db.go), which runs on every panel start (including a bare docker run/compose up with no extra command — DockerEntrypoint.sh just execs /app/x-ui, and x-ui with no subcommand calls the same runWebServer() as x-ui run), does two things automatically:

  • GORM AutoMigrate over all current models (new tables: clients, client_inbounds, hosts, nodes, api_tokens, client_groups, outbound_subscriptions, etc.).
  • A chain of one-time, self-gated seeders recorded in history_of_seeders, so each runs exactly once. The relevant one for you is ClientsTable: in v2.6.7 clients lived only inside each inbound's settings JSON blob; v3 normalizes them into the new clients/client_inbounds tables the first time it sees your DB, without touching the original JSON. Related seeders also backfill missing email, fix stringified tgId, and clean up legacy flow values.

You do not need to run x-ui migrate or migrate-db for this — that only applies to the separate SQLite→PostgreSQL path or extra one-off data cleanup. Just back up ./db/x-ui.db before switching the tag (stop the container first, then copy the file — it's a single file, no -wal/-shm sidecars, since the DB opens with journal_mode=DELETE).

2. REST API — yes, breaking changes, specifically for client management and auth

Comparing web/controller/api.go/inbound.go at tag v2.6.7 against the current internal/web/controller/:

  • Client endpoints moved and changed shape. In v2.6.7, client add/update/delete/traffic/IP endpoints lived under /panel/api/inbounds/* (e.g. POST /panel/api/inbounds/addClient, POST /panel/api/inbounds/updateClient/:clientId, POST /panel/api/inbounds/:id/delClient/:clientId, GET /panel/api/inbounds/getClientTraffics/:email), keyed by inbound id + a client id, with the whole Inbound object (including the JSON settings string) as the payload. In v3.4.2 these live under a new /panel/api/clients/* group (internal/web/controller/client.go): POST /add, POST /update/:email, POST /del/:email, GET /traffic/:email, POST /resetTraffic/:email, POST /onlines, etc. — keyed by client email (a client is now a normalized entity attachable to multiple inbounds), with a different JSON payload shape. Any bot code hard-coded to the old paths/payloads will get 404s or bind errors and needs to be rewritten against the new endpoints (current reference: the in-panel Swagger docs at /panel/api-docs, generated from source so it always matches the running build).
  • CSRF protection is new in v3 and will very likely break your bot's login flow. v2.6.7's API only required a valid login-session cookie (checkLogin) — there was no API-token concept at all (no apiToken setting existed in v2.6.7). v3 adds CSRF checks (internal/web/middleware/security.go, internal/web/session/csrf.go) to every unsafe method (POST/PUT/DELETE) authenticated via session cookie — including POST /login itself. A cookie-based client must first GET /panel/csrf-token (public, safe method) to obtain a token tied to its session, then send it back as the X-CSRF-Token header (or _csrf form field) on /login and every subsequent mutating call. If your bot currently just POSTs credentials to /login and reuses the cookie for POSTs, as was sufficient in v2.6.7, it will start getting 403 Forbidden.
  • Recommended fix: switch the bot to v3's Bearer-token auth instead of session cookies — it bypasses CSRF entirely (checkAPIAuth in internal/web/controller/api.go sets api_authed, which the CSRF middleware short-circuits on). Generate/view a token with docker exec -it <container> /app/x-ui setting -getApiToken, or from the panel under Settings → API Tokens, then send Authorization: Bearer <token> on every request.

3. Reality inbounds

I found no Reality-specific migration code (no rewrite of streamSettings.realitySettings anywhere in internal/database/), and no matching reports in this repo's issue tracker of Reality inbounds breaking specifically from a v2→v3 database upgrade. The raw JSON is carried through unchanged, so your existing Reality config should generate the same Xray config after upgrade. That said, I can't rule out unrelated bugs — after upgrading, check /panel → Xray logs (or docker logs) and confirm at least one client can still connect before considering the migration done.

Recommended upgrade sequence

  1. docker compose down (or stop the container), copy ./db/x-ui.db somewhere safe.
  2. Change the image tag to v3.4.2 and start it back up — schema/data migration happens automatically on that first boot.
  3. Log into the panel with your existing username/password to confirm the account and inbound/client data carried over.
  4. Update your Telegram bot to use /panel/api/clients/* (not /panel/api/inbounds/...Client...) and switch it to Authorization: Bearer <token> instead of session-cookie login.

This reply was generated automatically and a maintainer may follow up.

<!-- gh-comment-id:4850664714 --> @github-actions[bot] commented on GitHub (Jul 1, 2026): Short answer: yes, you can point `v3.4.2` at your existing `x-ui.db` — the schema migration is automatic. The part that will actually break is your custom Telegram bot's calls to the panel REST API, for two separate reasons detailed below. **1. Database schema — auto-migrated, no manual step needed** `database.InitDB` (`internal/database/db.go`), which runs on every panel start (including a bare `docker run`/`compose up` with no extra command — `DockerEntrypoint.sh` just execs `/app/x-ui`, and `x-ui` with no subcommand calls the same `runWebServer()` as `x-ui run`), does two things automatically: - GORM `AutoMigrate` over all current models (new tables: `clients`, `client_inbounds`, `hosts`, `nodes`, `api_tokens`, `client_groups`, `outbound_subscriptions`, etc.). - A chain of one-time, self-gated seeders recorded in `history_of_seeders`, so each runs exactly once. The relevant one for you is `ClientsTable`: in v2.6.7 clients lived only inside each inbound's `settings` JSON blob; v3 normalizes them into the new `clients`/`client_inbounds` tables the first time it sees your DB, without touching the original JSON. Related seeders also backfill missing `email`, fix stringified `tgId`, and clean up legacy flow values. You do not need to run `x-ui migrate` or `migrate-db` for this — that only applies to the separate SQLite→PostgreSQL path or extra one-off data cleanup. Just back up `./db/x-ui.db` before switching the tag (stop the container first, then copy the file — it's a single file, no `-wal`/`-shm` sidecars, since the DB opens with `journal_mode=DELETE`). **2. REST API — yes, breaking changes, specifically for client management and auth** Comparing `web/controller/api.go`/`inbound.go` at tag `v2.6.7` against the current `internal/web/controller/`: - *Client endpoints moved and changed shape.* In v2.6.7, client add/update/delete/traffic/IP endpoints lived under `/panel/api/inbounds/*` (e.g. `POST /panel/api/inbounds/addClient`, `POST /panel/api/inbounds/updateClient/:clientId`, `POST /panel/api/inbounds/:id/delClient/:clientId`, `GET /panel/api/inbounds/getClientTraffics/:email`), keyed by inbound id + a client `id`, with the whole `Inbound` object (including the JSON `settings` string) as the payload. In v3.4.2 these live under a new `/panel/api/clients/*` group (`internal/web/controller/client.go`): `POST /add`, `POST /update/:email`, `POST /del/:email`, `GET /traffic/:email`, `POST /resetTraffic/:email`, `POST /onlines`, etc. — keyed by client `email` (a client is now a normalized entity attachable to multiple inbounds), with a different JSON payload shape. Any bot code hard-coded to the old paths/payloads will get 404s or bind errors and needs to be rewritten against the new endpoints (current reference: the in-panel Swagger docs at `/panel/api-docs`, generated from source so it always matches the running build). - *CSRF protection is new in v3 and will very likely break your bot's login flow.* v2.6.7's API only required a valid login-session cookie (`checkLogin`) — there was no API-token concept at all (no `apiToken` setting existed in v2.6.7). v3 adds CSRF checks (`internal/web/middleware/security.go`, `internal/web/session/csrf.go`) to every unsafe method (POST/PUT/DELETE) authenticated via session cookie — including `POST /login` itself. A cookie-based client must first `GET /panel/csrf-token` (public, safe method) to obtain a token tied to its session, then send it back as the `X-CSRF-Token` header (or `_csrf` form field) on `/login` and every subsequent mutating call. If your bot currently just POSTs credentials to `/login` and reuses the cookie for POSTs, as was sufficient in v2.6.7, it will start getting `403 Forbidden`. - *Recommended fix:* switch the bot to v3's Bearer-token auth instead of session cookies — it bypasses CSRF entirely (`checkAPIAuth` in `internal/web/controller/api.go` sets `api_authed`, which the CSRF middleware short-circuits on). Generate/view a token with `docker exec -it <container> /app/x-ui setting -getApiToken`, or from the panel under Settings → API Tokens, then send `Authorization: Bearer <token>` on every request. **3. Reality inbounds** I found no Reality-specific migration code (no rewrite of `streamSettings.realitySettings` anywhere in `internal/database/`), and no matching reports in this repo's issue tracker of Reality inbounds breaking specifically from a v2→v3 database upgrade. The raw JSON is carried through unchanged, so your existing Reality config should generate the same Xray config after upgrade. That said, I can't rule out unrelated bugs — after upgrading, check /panel → Xray logs (or `docker logs`) and confirm at least one client can still connect before considering the migration done. **Recommended upgrade sequence** 1. `docker compose down` (or stop the container), copy `./db/x-ui.db` somewhere safe. 2. Change the image tag to `v3.4.2` and start it back up — schema/data migration happens automatically on that first boot. 3. Log into the panel with your existing username/password to confirm the account and inbound/client data carried over. 4. Update your Telegram bot to use `/panel/api/clients/*` (not `/panel/api/inbounds/...Client...`) and switch it to `Authorization: Bearer <token>` instead of session-cookie login. *This reply was generated automatically and a maintainer may follow up.*
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#3971
No description provided.