Skip to content

feat: drop solution-specific bundled build fields (contract) [4/4] - #851

Open
almeidaraul wants to merge 1 commit into
TO-404/3-migrate-read-newfrom
TO-404/4-drop-legacy-fields
Open

feat: drop solution-specific bundled build fields (contract) [4/4]#851
almeidaraul wants to merge 1 commit into
TO-404/3-migrate-read-newfrom
TO-404/4-drop-legacy-fields

Conversation

@almeidaraul

Copy link
Copy Markdown
Contributor

Stack

This is PR 4 of 4 in the TO-404 expand/contract split. Deploy in order — each PR must be merged and rolled out before the next:

  1. feat: add artefact.attributes JSONB column (expand) [1/3] #848 — add attributes field (expand)
  2. feat: mirror solution writes into artefact.attributes (write-both) [2/3] #849 — write to old and new fields
  3. feat: read solution data from attributes, stop writing legacy fields [3/3] #850 — backfill + read new + stop writing old
  4. this PR — drop the legacy solution-specific fields (contract)

Base: TO-404/3-migrate-read-new (#850).

What this does

The contract step of the rolling-upgrade sequence. After #850 has deployed (nothing reads or writes the legacy fields anymore), this removes them:

  • Drops the artefact.bundled_builds_hash column
  • Drops the artefact_bundled_builds_association table
  • Swaps the unique_solution index to a simple (name, version) uniqueness constraint
  • Resets the transitional alembic check expand/contract exclusions in env.py now that the ORM and DB schema agree again

Migration 8bd1f5009f02 revises the backfill migration d315c1f212b9.

⚠️ Deploy ordering

Merge and deploy only after #850 has merged and rolled out. The destructive migration includes a guard (_assert_no_duplicate_solutions) that refuses to run if duplicate solutions exist under the new (name, version) uniqueness — resolve any duplicates first.

Testing

  • alembic upgrade head + alembic check clean on a fresh DB (ORM matches schema)
  • Isolated migration test (upgrade/downgrade, guard behaviour): 8/8 pass
  • Model uniqueness tests + full ruff/mypy pass

@almeidaraul
almeidaraul force-pushed the TO-404/4-drop-legacy-fields branch from 36e311d to 07f007c Compare August 18, 2026 13:14
Contract step of the expand/contract rolling-upgrade sequence. After the
backfill + read-new release (#850) is deployed, remove the now-unused legacy
solution-specific fields:

- Drop `artefact.bundled_builds_hash` column
- Drop the `artefact_bundled_builds_association` table
- Swap the `unique_solution` index to a simple (name, version) uniqueness
- Reset the transitional `alembic check` expand/contract exclusions in env.py
  now that the ORM and DB schema agree again

Migration `8bd1f5009f02` revises the backfill migration `d315c1f212b9`.
Deploy only after #850 has merged and rolled out.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@almeidaraul
almeidaraul force-pushed the TO-404/4-drop-legacy-fields branch from 07f007c to 96424b7 Compare August 18, 2026 14:14
@almeidaraul
almeidaraul marked this pull request as ready for review August 18, 2026 15:07
Copilot AI lite review requested due to automatic review settings August 18, 2026 15:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Implements the contract step of the TO-404 expand/contract sequence by removing legacy, solution-specific bundled-build schema elements now that artefact.attributes is the source of truth. This keeps the ORM and DB schema aligned again (including alembic check) and tightens solution uniqueness to (name, version).

Changes:

  • Add destructive Alembic migration 8bd1f5009f02 to drop artefact.bundled_builds_hash and artefact_bundled_builds_association, and swap unique_solution to (name, version).
  • Remove transitional alembic check expand/contract ignore lists in backend/migrations/env.py.
  • Add/extend tests covering the contract migration and the updated solution uniqueness constraint.

Reviewed changes

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

File Description
backend/migrations/versions/2026_08_10_1716-8bd1f5009f02_drop_solution_specific_bundled_build_fields.py Contract migration: swap unique_solution, re-run backfill, then drop legacy column/table.
backend/migrations/env.py Reset expand/contract alembic check ignore sets now that schema and ORM match.
backend/tests/migrations/test_8bd1f5009f02_drop_solution_specific_bundled_build_fields.py New migration-level upgrade/downgrade/guard tests for the contract revision.
backend/tests/data_access/test_models.py Add uniqueness tests asserting solutions are unique on (name, version) regardless of source/track/stage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

conn, "solution-unknown-build", attributes='{"bundled_builds": [999999999]}'
)

# Raises a DatabaseError; after guarding the traversal it should complete cleanly.
Comment on lines +132 to +154
UPDATE artefact AS a
SET attributes = a.attributes
|| jsonb_strip_nulls(
jsonb_build_object('bundled_builds_hash', a.bundled_builds_hash)
)
|| COALESCE(
(
SELECT jsonb_build_object(
'bundled_builds',
jsonb_agg(assoc.artefact_build_id ORDER BY assoc.artefact_build_id)
)
FROM artefact_bundled_builds_association assoc
WHERE assoc.artefact_id = a.id
HAVING count(*) > 0
),
'{}'::jsonb
)
WHERE a.bundled_builds_hash IS NOT NULL
OR EXISTS (
SELECT 1
FROM artefact_bundled_builds_association assoc
WHERE assoc.artefact_id = a.id
)
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.

2 participants