Backport of 'Fix ci_finished_builds engine swap on deferred post-deploy' into 19.0

What does this MR do and why?

Backports !240219 (merged), !240627 (merged), and !240798 (merged) (merged commit b4f205d5) to 19-0-stable-ee.

ClickHouse post-deployment migration 20260108073937_alter_ci_finished_builds_engine_with_version failed in two ways on stable branches:

  1. Structure mismatch (#593129 (closed)): Code: 122. DB::Exception: Tables have different structure. (INCOMPATIBLE_COLUMNS) when self-managed customers upgrade from 18.8.x to 18.9.x–19.0.x. Root cause: hardcoded CREATE TABLE for the tmp table; later-timestamped migrations add columns/projections before this post-deploy migration runs. Fixed in master by !240219 (merged) (use CREATE TABLE ... AS source ENGINE = ... SETTINGS ...).

  2. Older-ClickHouse compatibility (uncovered while backporting): on CH 23.x/24.x the same CREATE TABLE ... AS source ENGINE = ... form does not implicitly inherit PARTITION BY / ORDER BY from the source. Fixed in master by !240627 (merged) (specify them explicitly). 19.0 only runs CH 25/26 so this wasn't strictly necessary here, but kept identical to master to maintain the strict-subset invariant for future cherry-picks.

This branch contains three cherry-picks from master:

commit from MR purpose
ca503ffb !240219 (merged) Initial fix: clone source structure via CREATE TABLE … AS source
d811b49f !240627 (merged) Explicit PARTITION BY / ORDER BY for CH 23.x/24.x compatibility
b4f205d5 !240798 (merged) drop_tmp_table DETACH+DROP path on CH 23.x, version-agnostic spec, dedup-gate threshold fix (CH 24.8+), self-healing create_tmp_table on retry, and a .pluck('name') rubocop fix in the spec for rubocop-rails 2.26+.

No conflicts. All three apply cleanly.

References

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

  • This MR is backporting a bug fix, documentation update, or spec fix, previously merged in the default branch.
  • The MR that fixed the bug on the default branch has been deployed to GitLab.com (not applicable for documentation or spec changes).
  • The MR title is descriptive (e.g. "Backport of 'title of default branch MR'"). This is important, since the title will be copied to the patch blog post.
  • Required labels have been applied to this merge request
  • This MR has been approved by a maintainer (only one approval is required).
  • Ensure the e2e:test-on-omnibus-ee job has succeeded, or if it has failed, investigate the failures. If you determine the failures are unrelated, you may proceed. If you need assistance investigating, request help in the #s_developer_experience Slack channel to confirm the failures are unrelated to the merge request.

Note to the merge request author and maintainer

If you have questions about the patch release process, please:

Edited by Narendran

Merge request reports

Loading