Skip to content

Replace rerun_of column with new bigint version - #9401

Merged
taylorsilva merged 6 commits into
masterfrom
8499-rerun-of-bigint
Jan 1, 2026
Merged

taylorsilva merged 6 commits into
masterfrom
8499-rerun-of-bigint

Conversation

@taylorsilva

@taylorsilva taylorsilva commented Dec 17, 2025 •

Copy link
Copy Markdown
Member

Changes proposed by this PR

closes #8499 and #9029

  • Renames existing rerun_of to rerun_of_old in the builds table
  • Adds a new column named rerun_of with type bigint
  • Rename indexes where rerun_of_old is used and create copies of the indexes referencing the new rerun_of column

Notes to reviewer

Tldr of the issue was that once your build id's surpassed the size supported by int in Postgresql, trying to re-run a build with an id larger than int would fail because the rerun_of column was of type int.

See the comments in #8499 which explains why we went this route. Tldr: shipping long-running migrations in an OSS project is hard.

TODO

  • Migration-level test that I can add? As-is, the db and scheduler tests are passing. I think I can add some tests in atc/db/migration Deciding to skip this, doesn't seem to result in long-term value IMO
  • Manual tests:
    • New rerun builds can be created of existing builds (rerun and non-rerun builds) after upgrading
    • Resource versions that passed old builds (before this migration) still pass downstream as expected

@taylorsilva

taylorsilva commented Dec 22, 2025 •

Copy link
Copy Markdown
Member Author

Going to merge this after #9402 is resolved. I should rebase on master as well to get the changes from that PR.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the rerun_of column in the builds table from integer to bigint to support build IDs that exceed the PostgreSQL integer limit (2^31-1). The migration strategy renames the existing column to rerun_of_old and creates a new rerun_of column as bigint, allowing both columns to coexist during the transition period. All queries are updated to use COALESCE(rerun_of, rerun_of_old) to check both columns.

Key Changes:

  • Database migration to rename builds.rerun_of to rerun_of_old and create new bigint rerun_of column
  • Updated all SQL queries to check both rerun_of and rerun_of_old columns using COALESCE
  • Added MaxInt32 optimization logic to avoid checking rerun_of_old when values exceed integer limits
  • Incidental code cleanups including removing unused parameters, simplifying conditionals, and modernizing Go loop syntax

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
atc/db/migration/migrations/1765921815_rerun_of_bigint.up.sql Adds migration to rename old rerun_of column and create new bigint version with updated indexes
atc/db/migration/migrations/1765921815_rerun_of_bigint.down.sql Provides rollback migration (contains issues with non-existent indexes)
atc/db/versions_db.go Updates queries to use COALESCE for both rerun_of columns and adds MaxInt32 optimization logic
atc/db/pipeline.go Updates LoadDebugVersionsDB to check both rerun_of columns
atc/db/job.go Updates job queries and adds MaxInt32-based query optimization for rerun counting
atc/db/build.go Updates build queries to handle both rerun_of columns during migration
atc/db/build_factory.go Updates build factory queries with COALESCE for rerun_of columns
atc/db/listener.go Moves context creation earlier in loop and adds cancel before return (introduces context leak)
atc/db/component_factory.go Removes redundant error check after QueryRow()
atc/db/migration/migration.go Simplifies else-if condition to else
atc/db/migration/parser.go Removes unused migrationContents parameter from determineMigrationStrategy
atc/db/migration/*_test.go Modernizes loop syntax using Go 1.22+ range over integers
atc/db/migration/migration_test.go Updates to use strings.SplitSeq with range iteration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread atc/db/listener.go Resolved
Comment thread atc/db/versions_db.go Resolved
Comment thread atc/db/job.go Resolved
@taylorsilva
taylorsilva force-pushed the 8499-rerun-of-bigint branch 2 times, most recently from 48682ce to aa4422b Compare December 31, 2025 00:51
* removed unused func param
* remove redundant nil check in if-else

Signed-off-by: Taylor Silva <[email protected]>
no point in referencing the rerun_of_old column if the build id is
larger than math.MaxInt32

Signed-off-by: Taylor Silva <[email protected]>
if there's an error with QueryRow() it'll be returned by scanComponent()

Signed-off-by: Taylor Silva <[email protected]>
an edge-case, but avoids accidently leaking the context

Signed-off-by: Taylor Silva <[email protected]>
@taylorsilva

Copy link
Copy Markdown
Member Author

Performed all the same manual tests I did in #9402 and everything worked.

@taylorsilva
taylorsilva merged commit c22de16 into master Jan 1, 2026
3 checks passed
@taylorsilva
taylorsilva deleted the 8499-rerun-of-bigint branch January 1, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migration for updating int to bigint takes long time for large Concourse deployments

2 participants