[PR #6995] [MERGED] fix(server): honor keepHostSettings for SQLite imports into PostgreSQL #6568

Closed
opened 2026-11-02 04:09:42 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6995
Author: @HamedSanaei
Created: 10/28/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @MHSanaei

Base: main ← Head: codex/issue-6993-keep-host-settings


📝 Commits (1)

  • 061fa1f fix(server): preserve host settings on SQLite imports into PostgreSQL

📊 Changes

3 files changed (+296 additions, -3 deletions)

View changed files

📝 .github/workflows/ci.yml (+9 -0)
➕ internal/web/service/import_sqlite_postgres_test.go (+276 -0)
📝 internal/web/service/server.go (+11 -3)

📄 Description

Summary

SQLite .db backups and SQLite SQL .dump imports into a PostgreSQL panel now honor Keep this machine's settings. With the option enabled, the destination retains its panel/subscription listen addresses, ports, paths, certificates and node identity; ordinary settings, users, inbounds and clients still come from the upload. Disabling it remains the intentional full-clone mode.

Fixes #6993. Related: #6227 and #5004.

Root cause and fix

importPostgresDB forwarded keepHostSettings only for native PostgreSQL dumps. Both SQLite branches discarded it, and MigrateData replaced the entire settings table.

Forward the flag for both SQLite formats. Reuse the existing host-bound snapshot/restore helpers: capture before closing the destination database, then restore only after migration succeeds and the database reopens. This retains the existing distinction between absent rows, explicitly empty values, and absent lazily generated mTLS material. A failed copy retains the existing transactional rollback/reopen behavior and does not reapply the snapshot over the rolled-back database.

The production change is limited to this SQLite-to-PostgreSQL service path. Native PostgreSQL dump restore, SQLite-panel imports, the CLI migration command, frontend/API contracts, and database schema are unchanged. Existing helper error-handling semantics are reused.

Regression coverage

The new integration test calls the public ServerService.ImportDB with actual SQLite files/SQL dumps and a real PostgreSQL destination. Each case uses a private schema and removes it afterward; the Xray executable is a harmless temporary process fixture, so no real panel/core installation is required.

16 scenarios cover both formats with keep enabled/disabled and:

  • All local host-bound settings present, including panel/subscription ports and paths, bind/certificate settings, secret, GUID and all node mTLS rows.
  • Mixed missing and explicitly empty local rows, including the existing rule that missing lazily generated key material keeps the imported copy.
  • No local host-setting rows at all.
  • A real PostgreSQL CHECK constraint rejecting the incoming settings copy after the migration has begun. Settings, users, inbounds and clients stay local after rollback; an audit trigger proves that host-setting restoration does not run on this failure path.

Successful cases also verify that source users, clients, inbounds and an ordinary setting are imported, replacing the destination data. The existing postgres-migration CI job now explicitly runs this suite and checks for its top-level PASS line, so a skipped/deleted test cannot silently satisfy the gate.

Validation

Executed locally with Go 1.27.3 and a dedicated PostgreSQL 16 container:

  • Before the service fix, all 6 keep-enabled successful-migration cases failed, reproducing replacement by source values for both formats. The full-clone and rollback controls passed.
  • go test ./internal/web/service -run '^TestImportSQLiteIntoPostgresHostSettings$' -count=1 -v — 16 scenarios passed against real PostgreSQL.
  • Same integration suite with -race — 16 scenarios passed, no race reports.
  • go test ./internal/web/service ./internal/database -shuffle=on -count=1 — passed with the ordinary SQLite test environment; PostgreSQL-only cases are exercised separately above.
  • go vet ./internal/web/service ./internal/database — passed.
  • golangci-lint run ./internal/web/service/... — passed, 0 issues.
  • go run github.com/rhysd/actionlint/cmd/actionlint@v1.7.12 -color -shellcheck= — passed.
  • gofmt, git diff --check, and git diff --cached --check — passed.

No production database or running panel was used, and no live UI/HTTP restore or native pg_restore operation was performed. No deployment or merge is included.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6995 **Author:** [@HamedSanaei](https://github.com/HamedSanaei) **Created:** 10/28/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `codex/issue-6993-keep-host-settings` --- ### 📝 Commits (1) - [`061fa1f`](https://github.com/MHSanaei/3x-ui/commit/061fa1fc0a2b486051fda5d4a865367d6d96e40c) fix(server): preserve host settings on SQLite imports into PostgreSQL ### 📊 Changes **3 files changed** (+296 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/ci.yml` (+9 -0) ➕ `internal/web/service/import_sqlite_postgres_test.go` (+276 -0) 📝 `internal/web/service/server.go` (+11 -3) </details> ### 📄 Description ## Summary SQLite `.db` backups and SQLite SQL `.dump` imports into a PostgreSQL panel now honor **Keep this machine's settings**. With the option enabled, the destination retains its panel/subscription listen addresses, ports, paths, certificates and node identity; ordinary settings, users, inbounds and clients still come from the upload. Disabling it remains the intentional full-clone mode. Fixes #6993. Related: #6227 and #5004. ## Root cause and fix `importPostgresDB` forwarded `keepHostSettings` only for native PostgreSQL dumps. Both SQLite branches discarded it, and `MigrateData` replaced the entire settings table. Forward the flag for both SQLite formats. Reuse the existing host-bound snapshot/restore helpers: capture before closing the destination database, then restore only after migration succeeds and the database reopens. This retains the existing distinction between absent rows, explicitly empty values, and absent lazily generated mTLS material. A failed copy retains the existing transactional rollback/reopen behavior and does not reapply the snapshot over the rolled-back database. The production change is limited to this SQLite-to-PostgreSQL service path. Native PostgreSQL dump restore, SQLite-panel imports, the CLI migration command, frontend/API contracts, and database schema are unchanged. Existing helper error-handling semantics are reused. ## Regression coverage The new integration test calls the public `ServerService.ImportDB` with actual SQLite files/SQL dumps and a real PostgreSQL destination. Each case uses a private schema and removes it afterward; the Xray executable is a harmless temporary process fixture, so no real panel/core installation is required. **16 scenarios** cover both formats with keep enabled/disabled and: - All local host-bound settings present, including panel/subscription ports and paths, bind/certificate settings, secret, GUID and all node mTLS rows. - Mixed missing and explicitly empty local rows, including the existing rule that missing lazily generated key material keeps the imported copy. - No local host-setting rows at all. - A real PostgreSQL CHECK constraint rejecting the incoming settings copy after the migration has begun. Settings, users, inbounds and clients stay local after rollback; an audit trigger proves that host-setting restoration does not run on this failure path. Successful cases also verify that source users, clients, inbounds and an ordinary setting are imported, replacing the destination data. The existing `postgres-migration` CI job now explicitly runs this suite and checks for its top-level PASS line, so a skipped/deleted test cannot silently satisfy the gate. ## Validation Executed locally with Go 1.27.3 and a dedicated PostgreSQL 16 container: - Before the service fix, all **6 keep-enabled successful-migration cases failed**, reproducing replacement by source values for both formats. The full-clone and rollback controls passed. - `go test ./internal/web/service -run '^TestImportSQLiteIntoPostgresHostSettings$' -count=1 -v` — **16 scenarios passed** against real PostgreSQL. - Same integration suite with `-race` — **16 scenarios passed**, no race reports. - `go test ./internal/web/service ./internal/database -shuffle=on -count=1` — passed with the ordinary SQLite test environment; PostgreSQL-only cases are exercised separately above. - `go vet ./internal/web/service ./internal/database` — passed. - `golangci-lint run ./internal/web/service/...` — passed, **0 issues**. - `go run github.com/rhysd/actionlint/cmd/actionlint@v1.7.12 -color -shellcheck=` — passed. - `gofmt`, `git diff --check`, and `git diff --cached --check` — passed. No production database or running panel was used, and no live UI/HTTP restore or native `pg_restore` operation was performed. No deployment or merge is included. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi changed title from [PR #6995] fix(server): honor keepHostSettings for SQLite imports into PostgreSQL to [PR #6995] [MERGED] fix(server): honor keepHostSettings for SQLite imports into PostgreSQL 2026-11-07 14:34:01 +07:00
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#6568
No description provided.