-
Notifications
You must be signed in to change notification settings - Fork 12
TO-404: remove solution-specific fields #835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a54540f
feat: add attributes JSONB to artefacts and remove solution-specific …
almeidaraul a631e11
tests: solutions request behaviour
almeidaraul c54b778
enh: copilot review
almeidaraul 7f249ee
fix: undo local-only change to test_saml
almeidaraul e831c14
enh: copilot review
almeidaraul 25a5d31
fix: licensing in migration
almeidaraul ae13ae2
enh: copilot review
almeidaraul c27112e
enh: copilot review
almeidaraul 18a6246
enh: copilot review
almeidaraul ff46d9d
enh: copilot review (2)
almeidaraul 956db97
fix: failing CI due to diff in schema types (thx copilot)
almeidaraul 3f95db8
Merge remote-tracking branch 'origin/main' into TO-404/remove-solutio…
almeidaraul f4b129b
enh: small review points from Will
almeidaraul 87def61
enh: split into 2 migrations (to-do: split into 2 PRs)
almeidaraul 4021913
fix: failing test
almeidaraul 08b4e9e
fix: schema
almeidaraul cf9032d
chore: remove destructive migration from this branch
almeidaraul 19079e8
chore: remove test that only belongs to next PR
almeidaraul 94cf63e
chore: linting
almeidaraul 58ffaa1
fix: alembic check
almeidaraul 8045933
Merge remote-tracking branch 'origin/main' into TO-404/remove-solutio…
almeidaraul 04f8694
fix: mypy
almeidaraul a4cb61a
fix: linting
almeidaraul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
.../migrations/versions/2026_07_21_1311-8202f7b5953e_add_artefact_attributes_and_backfill.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # Copyright 2026 Canonical Ltd. | ||
| # | ||
| # This program is free software: you can redistribute it and/or modify | ||
| # it under the terms of the GNU Affero General Public License version 3, as | ||
| # published by the Free Software Foundation. | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU Affero General Public License for more details. | ||
| # You should have received a copy of the GNU Affero General Public License | ||
| # along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| # | ||
| # SPDX-FileCopyrightText: Copyright 2026 Canonical Ltd. | ||
| # SPDX-License-Identifier: AGPL-3.0-only | ||
|
|
||
| """Add artefact.attributes and backfill bundled builds into it | ||
|
|
||
| This is the non-destructive (expand) half of adding the ``attributes`` column | ||
| to artefacts and removing solution-specific fields. | ||
|
|
||
| It only adds the new column and copies existing data into it, leaving | ||
| ``bundled_builds_hash`` and ``artefact_bundled_builds_association`` in place | ||
| so that code running against the old schema keeps working during a rolling | ||
| upgrade. | ||
|
|
||
| The destructive (contract) half - swapping the ``unique_solution`` index and | ||
| dropping the old column/table - lives in a separate, later migration that must | ||
| be released only after this one has been fully rolled out. | ||
|
|
||
| Revision ID: 8202f7b5953e | ||
| Revises: eba1d1c92dba | ||
| Create Date: 2026-07-21 13:11:39.128081+00:00 | ||
|
|
||
| """ | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
| from sqlalchemy.dialects import postgresql | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "8202f7b5953e" | ||
| down_revision = "eba1d1c92dba" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.add_column("artefact", sa.Column("attributes", postgresql.JSONB(), server_default="{}", nullable=False)) | ||
| _copy_bundled_builds_to_attributes() | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_column("artefact", "attributes") | ||
|
|
||
|
|
||
| def _copy_bundled_builds_to_attributes() -> None: | ||
| op.execute( | ||
| """ | ||
| 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 | ||
| ) | ||
| """ | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.