mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #4787] [Bug]: #3322
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#3322
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @MaNixBlacks on GitHub (Jun 2, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4787
Describe the bug
Database migration is not occurring on version 3.2.5.
How to reproduce the problem
update to 3.2.5
x-ui
27
2
INF] Stopping panel to take a consistent snapshot...
[INF] Migrating data into PostgreSQL...
2026/06/02 01:14:25 Creating destination schema...
2026/06/02 01:14:25 User 1 rows
2026/06/02 01:14:25 Setting 5 rows
2026/06/02 01:14:25 HistoryOfSeeders 6 rows
2026/06/02 01:14:25 CustomGeoResource 0 rows
2026/06/02 01:14:25 Node 0 rows
2026/06/02 01:14:25 ApiToken 0 rows
2026/06/02 01:14:25 Inbound 1 rows
2026/06/02 01:14:26 ClientTraffic 19730 rows
2026/06/02 01:14:26 OutboundTraffics 0 rows
2026/06/02 01:14:26 InboundClientIps 0 rows
2026/06/02 01:14:26 ClientRecord 19730 rows
migration failed: copy *model.ClientInbound: primary key required
[ERR] Migration failed. The panel was NOT switched to PostgreSQL.
1. Install PostgreSQL (server + client + xui db)
2. Migrate SQLite -> PostgreSQL
3. Status (clusters & port 5432)
4. Start PostgreSQL
5. Stop PostgreSQL
6. Restart PostgreSQL
7. Enable Autostart on boot
8. View PostgreSQL Log
0. Back to Main Menu
Choose an option:
20 000 clients error migration ==((
Expected behavior
No response
Actual behavior
No response
Relevant logs
Screenshots
No response
3x-ui version
3.2.5
Xray-core version
No response
How did you install 3x-ui?
install.sh script
Operating system
Ubuntu 24,04
Which parts of the panel are affected?
Database / migrations
Browser (only if it is a UI bug)
No response
Is the panel behind a reverse proxy or CDN?
None
Before submitting
@github-actions[bot] commented on GitHub (Jun 2, 2026):
Thank you for the detailed report!
The error 'migration failed: copy *model.ClientInbound: primary key required' points to a failure when copying the client_inbounds junction table (which links clients to inbounds). This table uses a composite primary key (client_id + inbound_id), and GORM's batch-insert rejects records where either key field is zero-valued.
With 19,730 clients this is a realistic scenario — some client_inbounds rows in your SQLite database likely have a zero value in one of those columns (e.g. an orphaned or unresolved client link), causing the whole batch to be rejected.
To diagnose, run this against your SQLite database before migrating:
If the count is > 0, those rows are the cause.
Workaround to unblock yourself:
Then retry the migration. This removes orphaned link rows that have no valid client or inbound reference — they should not affect actual traffic or client configuration.
This looks like a bug in the migration code that should skip or handle zero-value primary key rows gracefully rather than failing. Tagging for developer review.
@MHSanaei commented on GitHub (Jun 2, 2026):
Fixed.
Root cause: the SQLite→PostgreSQL copy used gorm's
FindInBatches, which pages between batches using a single "prioritized" primary field.client_inboundshas a composite primary key (client_id+inbound_id) with no surrogateidand no auto-increment, so gorm leaves itsPrioritizedPrimaryFieldnil and returnsErrPrimaryKeyRequired. The check only triggers once a table returns a full batch (>500 rows), which is why it reproduces on large installs and fails right afterClientRecord.This is unrelated to zero-value/orphaned rows —
gorm.Createdoes not raise that error andclient_inboundshas no FK constraints.Fix:
copyTablenow pages with explicitLIMIT/OFFSETordered by each model's primary-key columns instead ofFindInBatches. It handles composite-key tables, keeps memory bounded, and changes no schema. Added a Postgres-backed regression test that migrates a >500-row composite-key table.Verified in Docker (golang:1.26-alpine + postgres:16-alpine): the seeded 600-row
client_inboundstable now migrates cleanly where it previously failed withcopy *model.ClientInbound: primary key required.