Skip to content
Open
Show file tree
Hide file tree
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 Jul 21, 2026
a631e11
tests: solutions request behaviour
almeidaraul Jul 23, 2026
c54b778
enh: copilot review
almeidaraul Jul 23, 2026
7f249ee
fix: undo local-only change to test_saml
almeidaraul Jul 23, 2026
e831c14
enh: copilot review
almeidaraul Jul 23, 2026
25a5d31
fix: licensing in migration
almeidaraul Jul 23, 2026
ae13ae2
enh: copilot review
almeidaraul Jul 23, 2026
c27112e
enh: copilot review
almeidaraul Jul 23, 2026
18a6246
enh: copilot review
almeidaraul Jul 24, 2026
ff46d9d
enh: copilot review (2)
almeidaraul Jul 24, 2026
956db97
fix: failing CI due to diff in schema types (thx copilot)
almeidaraul Jul 24, 2026
3f95db8
Merge remote-tracking branch 'origin/main' into TO-404/remove-solutio…
almeidaraul Aug 10, 2026
f4b129b
enh: small review points from Will
almeidaraul Aug 10, 2026
87def61
enh: split into 2 migrations (to-do: split into 2 PRs)
almeidaraul Aug 11, 2026
4021913
fix: failing test
almeidaraul Aug 11, 2026
08b4e9e
fix: schema
almeidaraul Aug 11, 2026
cf9032d
chore: remove destructive migration from this branch
almeidaraul Aug 11, 2026
19079e8
chore: remove test that only belongs to next PR
almeidaraul Aug 12, 2026
94cf63e
chore: linting
almeidaraul Aug 12, 2026
58ffaa1
fix: alembic check
almeidaraul Aug 12, 2026
8045933
Merge remote-tracking branch 'origin/main' into TO-404/remove-solutio…
almeidaraul Aug 12, 2026
04f8694
fix: mypy
almeidaraul Aug 12, 2026
a4cb61a
fix: linting
almeidaraul Aug 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/test_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ jobs:
- name: Check if alembic migrations are up to date
run: docker compose exec test-observer-api alembic check
- name: Compare schema with repository
run: diff <(curl -s http://localhost:30000/openapi.json | jq) schemata/openapi.json
# Normalise integer-valued floats so the comparison is stable across jq
# versions (jq 1.6 on jammy canonicalises 1000000.0 -> 1000000 while jq
# 1.7 preserves the literal). Keep this filter in sync with
# scripts/fetch_openapi_schema.sh.
run: diff <(curl -s http://localhost:30000/openapi.json | jq 'walk(if type == "number" and floor == . then floor else . end)') schemata/openapi.json
- name: Ensure all endpoints are secured
run: ./scripts/check_endpoint_permissions.sh schemata/openapi.json
22 changes: 22 additions & 0 deletions backend/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@
fileConfig(config.config_file_name)


# Note: transitional expand/contract exclusions
# `alembic check` complains that the ORM models don't reference legacy solution-
# specific fields that were replaced by the `attributes` field. This happens
# because we are doing expand/contract migrations (for two separate releases);
# the following release will remove these exceptions.
_EXPAND_CONTRACT_IGNORED_TABLES: set[str] = {"artefact_bundled_builds_association"}
_EXPAND_CONTRACT_IGNORED_COLUMNS: set[tuple[str, str]] = {("artefact", "bundled_builds_hash")}
_EXPAND_CONTRACT_IGNORED_INDEXES: set[str] = {"unique_solution"}


def include_object(object, name, type_, reflected, compare_to): # noqa: ANN001, ANN201, ARG001
if type_ == "table" and name in _EXPAND_CONTRACT_IGNORED_TABLES:
return False
if type_ == "column":
table_name = object.table.name if object.table is not None else None
if (table_name, name) in _EXPAND_CONTRACT_IGNORED_COLUMNS:
return False
return not (type_ == "index" and name in _EXPAND_CONTRACT_IGNORED_INDEXES)


# Don't overwrite value if set by tests
if config.get_main_option("sqlalchemy.url") is None:
config.set_main_option("sqlalchemy.url", DB_URL)
Expand All @@ -52,6 +72,7 @@ def run_migrations_offline() -> None:
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
include_object=include_object,
)

with context.begin_transaction():
Expand All @@ -76,6 +97,7 @@ def run_migrations_online() -> None:
connection=connection,
target_metadata=target_metadata,
transaction_per_migration=True,
include_object=include_object,
)

with context.begin_transaction():
Expand Down
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()
Comment thread
almeidaraul marked this conversation as resolved.


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
)
"""
)
100 changes: 40 additions & 60 deletions backend/schemata/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -5668,13 +5668,6 @@
},
"type": "array",
"title": "Test Executions"
},
"bundled_in": {
"items": {
"$ref": "#/components/schemas/ArtefactMinimalResponse"
},
"type": "array",
"title": "Bundled In"
}
},
"type": "object",
Expand Down Expand Up @@ -6299,34 +6292,6 @@
"title": "ArtefactMatchingRuleResponse",
"description": "Artefact matching rule with associated teams"
},
"ArtefactMinimalResponse": {
"properties": {
"id": {
"type": "integer",
"title": "Id"
},
"name": {
"type": "string",
"title": "Name"
},
"version": {
"type": "string",
"title": "Version"
},
"family": {
"type": "string",
"title": "Family"
}
},
"type": "object",
"required": [
"id",
"name",
"version",
"family"
],
"title": "ArtefactMinimalResponse"
},
"ArtefactPatch": {
"properties": {
"status": {
Expand Down Expand Up @@ -6382,20 +6347,17 @@
],
"title": "Jira Issue"
},
"bundled_builds": {
"attributes": {
"anyOf": [
{
"items": {
"type": "integer"
},
"type": "array"
"additionalProperties": true,
"type": "object"
},
{
"type": "null"
}
],
"title": "Bundled Builds",
"description": "List of ArtefactBuild IDs to bundle with this artefact"
"title": "Attributes"
},
"assignee_id": {
"anyOf": [
Expand Down Expand Up @@ -6530,6 +6492,11 @@
"type": "string",
"title": "Comment"
},
"attributes": {
"additionalProperties": true,
"type": "object",
"title": "Attributes"
},
"archived": {
"type": "boolean",
"title": "Archived"
Expand Down Expand Up @@ -6581,13 +6548,6 @@
"type": "integer",
"title": "Completed Environment Reviews Count"
},
"bundled_builds": {
"items": {
"$ref": "#/components/schemas/ArtefactBuildMinimalResponse"
},
"type": "array",
"title": "Bundled Builds"
},
"assignee": {
"anyOf": [
{
Expand Down Expand Up @@ -6621,6 +6581,7 @@
"family",
"status",
"comment",
"attributes",
"archived",
"reviewers",
"due_date",
Expand Down Expand Up @@ -8518,20 +8479,41 @@
"const": "solution",
"title": "Family"
},
"attributes": {
"additionalProperties": true,
"type": "object",
"title": "Attributes"
},
"execution_stage": {
"$ref": "#/components/schemas/SolutionStage",
"description": "Promotion stage of the solution being tested."
},
"track": {
"type": "string",
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Track",
"description": "Solution release track being tested. Tracks represent different versions or streams of the solution. Examples: 'latest' (default), version-based tracks like '1.0', '2.0'. Use 'latest' if unsure."
"description": "Legacy field. Merged into attributes['track'] when attributes['track'] is not provided.",
"deprecated": true
},
"source": {
"type": "string",
"maxLength": 200,
"anyOf": [
{
"type": "string",
"maxLength": 200
},
{
"type": "null"
}
],
"title": "Source",
"description": "Source identifier for the solution. This identifies the packaging source or origin of the solution. Examples: 'ppa:team/ppa-name', 'custom-repo', 'internal-source'."
},
"execution_stage": {
"$ref": "#/components/schemas/SolutionStage",
"description": "Distribution channel/risk level of the solution being tested. Options: 'edge' (cutting-edge updates), 'beta' (pre-release), 'candidate' (release candidate), 'stable' (production). Choose based on where the solution currently resides in the release pipeline."
"description": "Legacy field. Merged into attributes['source'] when attributes['source'] is not provided.",
"deprecated": true
}
},
"type": "object",
Expand All @@ -8542,8 +8524,6 @@
"environment",
"test_plan",
"family",
"track",
"source",
"execution_stage"
],
"title": "StartSolutionTestExecutionRequest"
Expand Down
7 changes: 6 additions & 1 deletion backend/scripts/fetch_openapi_schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR/.."

tmpfile=$(mktemp)
# Normalise integer-valued floats (e.g. 1000000.0 -> 1000000) so the committed
# schema is stable across jq versions. jq 1.7 preserves number literals while
# jq 1.6 (used on the jammy CI runner) canonicalises them, which otherwise
# causes spurious diffs in the "Compare schema with repository" CI step.
normalise='walk(if type == "number" and floor == . then floor else . end)'
if curl --silent --fail "http://localhost:30000/openapi.json" -o "$tmpfile"; then
jq < "$tmpfile" > schemata/openapi.json
jq "$normalise" < "$tmpfile" > schemata/openapi.json
echo "OpenAPI schema fetched and written to schemata/openapi.json"
else
echo "Failed to fetch openapi.json"
Expand Down
Loading
Loading