8000 Fix embedded restore-database-mapping by preserving original table names by dfdemar · Pull Request #1659 · Altinity/clickhouse-backup · GitHub
[go: up one dir, main page]

Skip to content

Fix embedded restore-database-mapping by preserving original table names - #1659

Merged
Slach merged 3 commits into
Altinity:masterfrom
dfdemar:fix-restore-database-mapping
Nov 2, 2026
Merged

Slach merged 3 commits into
Altinity:masterfrom
dfdemar:fix-restore-database-mapping

Conversation

@dfdemar
@dfdemar dfdemar commented Oct 30, 2026 •
Copy link
Copy Markdown
Contributor

fix #1658

Changes

  • Add non-serialized OriginalDatabase/OriginalTable fields to TableMetadata to hold the names as they exist inside the backup
  • Record those names in changeTableQueryToAdjustDatabaseMapping and changeTableQueryToAdjustTableMapping before Database/Table are overwritten with the target
    • The table-mapping version keeps the true origin when database mapping has already run
  • Add embeddedRestoreObjectSQL, which builds <kind> <origin> AS <target> whenever the original and target names differ
  • Use it in restoreEmbedded, replacing the lookup keyed on the already-overwritten t.Database
    • This also makes --restore-table-mapping work for embedded backups
  • Add unit tests:
    • Both mapping functions record the original names
    • A table-driven test of the RESTORE SQL for no mapping, database mapping, database + table mapping, and a dictionary

…mes so RESTORE emits "AS <target>" instead of failing with code 605
RESTORE TABLE src AS dst doesn't create the target database when it is
absent in the backup, and for --tables=db.table restoreEmptyDatabase
skips it, so embedded restore with --restore-database-mapping failed
with code 81 even after the AS fix. Create mapped target databases in
restoreSchemaEmbedded the same way restoreSchemaRegular does.

Add testflows scenario generic/embedded_restore_mapping: embedded backup
to S3, restore_remote with --restore-database-mapping and
--restore-table-mapping, source table stays untouched. Fails on master
with code 605, passes with this branch.

Fixes Altinity#1658

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread pkg/backup/restore.go Resolved
…ded.py

- move mapped target database creation out of restoreSchemaEmbedded
  into createMappedDatabasesForEmbedded
- rename tests/embedded_on_cluster.py to tests/embedded.py and move
  embedded_restore_mapping there; new `embedded` feature runs the
  ON CLUSTER feature and the mapping scenario, ON CLUSTER scenarios are
  listed explicitly so the mapping scenario doesn't run with the
  ON CLUSTER config; the 23.3 gate lives once in `embedded`

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Slach
Slach merged commit 7982a44 into Altinity:master Nov 2, 2026
30 checks passed
@dfdemar
dfdemar deleted the fix-restore-database-mapping branch November 2, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

restore_remote --restore-database-mapping fails for embedded backups with Table <database.table_name> not found in backup

2 participants

0