Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
88 changes: 88 additions & 0 deletions migrations/versions/0e647dd16ef6_add_esm_app_legacy_pocket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
"""empty message

Revision ID: 0e647dd16ef6
Revises: fc4b8f31d182
Create Date: 2026-05-22 12:02:19.267122

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '0e647dd16ef6'
down_revision = 'fc4b8f31d182'
branch_labels = None
depends_on = None

# Enum 'type' for PostgreSQL
enum_name = 'pockets'
# Set temporary enum 'type' for PostgreSQL
tmp_enum_name = 'tmp_' + enum_name

# Options for Enum
old_options = (
'security',
'updates',
'esm-infra',
'esm-infra-legacy',
'esm-apps',
'fips',
'fips-updates',
'ros-esm',
'soss',
'realtime',
)
new_options = (
'security',
'updates',
'esm-infra',
'esm-infra-legacy',
'esm-apps',
'esm-apps-legacy',
'fips',
'fips-updates',
'ros-esm',
'soss',
'realtime',
)

# Create enum fields
old_type = sa.Enum(*old_options, name=enum_name)
new_type = sa.Enum(*new_options, name=enum_name)


def upgrade():
# Rename current enum type to tmp_
op.execute('ALTER TYPE ' + enum_name + ' RENAME TO ' + tmp_enum_name)
# Create new enum type in db
new_type.create(op.get_bind())
# Update column to use new enum type
op.execute(
'ALTER TABLE status ALTER COLUMN pocket TYPE '
+ enum_name
+ ' USING pocket::text::'
+ enum_name
)
# Drop old enum type
op.execute('DROP TYPE ' + tmp_enum_name)


def downgrade():
# Downgrade safety: map removed value to a compatible one.
op.execute(
"UPDATE status SET pocket = 'esm-apps' WHERE pocket = 'esm-apps-legacy'"
)
# Rename enum type to tmp_
op.execute('ALTER TYPE ' + enum_name + ' RENAME TO ' + tmp_enum_name)
# Create enum type using old values
old_type.create(op.get_bind())
# Set enum type as type for pocket column
op.execute(
'ALTER TABLE status ALTER COLUMN pocket TYPE '
+ enum_name
+ ' USING pocket::text::'
+ enum_name
)
# Drop temp enum type
op.execute('DROP TYPE ' + tmp_enum_name)
27 changes: 27 additions & 0 deletions tests/fixtures/payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,33 @@
"status": "active",
}

cve9 = {
"id": "CVE-9999-0009",
"codename": "testcodename9",
"packages": [
{
"debian": "https://tracker.debian.org/pkg/legacy-package",
"name": "legacy-package",
"source": "https://ubuntu.com/security/cve?package=legacy-package",
"statuses": [
{
"description": "",
"release_codename": "testrelease",
"status": "released",
"pocket": "esm-apps-legacy",
}
],
"ubuntu": (
"https://packages.ubuntu.com/search?suite=all&section=all&arch"
"=any&searchon=sourcenames&keywords=legacy-package"
),
}
],
"published": "2020-12-01 12:42:54",
"priority": "negligible",
"status": "active",
}

notice = {
"cves": ["CVE-9999-0003", "CVE-9999-0004"],
"id": "USN-9999-01",
Expand Down
6 changes: 6 additions & 0 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ def test_bulk_upsert_cves(self):
payloads.cve1,
payloads.cve2,
payloads.cve3,
payloads.cve9,
],
)
assert response_3.status_code == 200
Expand All @@ -1092,6 +1093,11 @@ def test_bulk_upsert_cves(self):
)
assert response.status_code == 200

response = self.client.get(
f"/security/cves/{payloads.cve9['id']}.json"
)
assert response.status_code == 200

def test_delete_non_existing_cve_returns_404(self):
response = self.client.delete(
f"/security/updates/cves/{payloads.cve1['id']}.json"
Expand Down
1 change: 1 addition & 0 deletions webapp/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"esm-infra",
"esm-infra-legacy",
"esm-apps",
"esm-apps-legacy",
"soss",
"fips",
"fips-updates",
Expand Down
Loading