Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a028f0-a42f-7582-89a8-ebaad7343834
88 lines
4.1 KiB
Python
88 lines
4.1 KiB
Python
"""Initial SBOM Nexus repository, snapshot, and entry schema.
|
|
|
|
Revision ID: 0001
|
|
Revises:
|
|
Create Date: 2026-08-22
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
revision = "0001"
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"repositories",
|
|
sa.Column("id", sa.String(length=36), nullable=False),
|
|
sa.Column("slug", sa.String(length=200), nullable=False),
|
|
sa.Column("checkout_path", sa.Text(), nullable=True),
|
|
sa.Column("active", sa.Boolean(), nullable=False),
|
|
sa.Column("last_attempt_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("last_success_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("last_status", sa.String(length=50), nullable=True),
|
|
sa.Column("last_source", sa.String(length=200), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.PrimaryKeyConstraint("id", name=op.f("pk_repositories")),
|
|
sa.UniqueConstraint("slug", name=op.f("uq_repositories_slug")),
|
|
)
|
|
op.create_table(
|
|
"snapshots",
|
|
sa.Column("id", sa.String(length=36), nullable=False),
|
|
sa.Column("repo_id", sa.String(length=36), nullable=False),
|
|
sa.Column("snapshot_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column("source", sa.String(length=200), nullable=False),
|
|
sa.Column("status", sa.String(length=50), nullable=False),
|
|
sa.Column("entry_count", sa.Integer(), nullable=False),
|
|
sa.Column("source_revision", sa.String(length=200), nullable=True),
|
|
sa.Column("sources_json", sa.JSON(), nullable=False),
|
|
sa.Column("errors_json", sa.JSON(), nullable=False),
|
|
sa.Column("legacy_id", sa.String(length=100), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.ForeignKeyConstraint(
|
|
["repo_id"], ["repositories.id"], name=op.f("fk_snapshots_repo_id_repositories"), ondelete="RESTRICT"
|
|
),
|
|
sa.PrimaryKeyConstraint("id", name=op.f("pk_snapshots")),
|
|
sa.UniqueConstraint("legacy_id", name=op.f("uq_snapshots_legacy_id")),
|
|
)
|
|
op.create_index("ix_snapshots_repo_time", "snapshots", ["repo_id", "snapshot_at"])
|
|
op.create_table(
|
|
"entries",
|
|
sa.Column("id", sa.String(length=36), nullable=False),
|
|
sa.Column("repo_id", sa.String(length=36), nullable=False),
|
|
sa.Column("snapshot_id", sa.String(length=36), nullable=False),
|
|
sa.Column("package_name", sa.String(length=300), nullable=False),
|
|
sa.Column("package_version", sa.String(length=100), nullable=True),
|
|
sa.Column("ecosystem", sa.String(length=50), nullable=False),
|
|
sa.Column("license_spdx", sa.String(length=100), nullable=True),
|
|
sa.Column("is_direct", sa.Boolean(), nullable=False),
|
|
sa.Column("is_dev", sa.Boolean(), nullable=False),
|
|
sa.Column("source_path", sa.Text(), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.ForeignKeyConstraint(
|
|
["repo_id"], ["repositories.id"], name=op.f("fk_entries_repo_id_repositories"), ondelete="RESTRICT"
|
|
),
|
|
sa.ForeignKeyConstraint(
|
|
["snapshot_id"], ["snapshots.id"], name=op.f("fk_entries_snapshot_id_snapshots"), ondelete="RESTRICT"
|
|
),
|
|
sa.PrimaryKeyConstraint("id", name=op.f("pk_entries")),
|
|
)
|
|
op.create_index("ix_entries_license", "entries", ["license_spdx"])
|
|
op.create_index("ix_entries_repo", "entries", ["repo_id"])
|
|
op.create_index("ix_entries_snapshot", "entries", ["snapshot_id"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_entries_snapshot", table_name="entries")
|
|
op.drop_index("ix_entries_repo", table_name="entries")
|
|
op.drop_index("ix_entries_license", table_name="entries")
|
|
op.drop_table("entries")
|
|
op.drop_index("ix_snapshots_repo_time", table_name="snapshots")
|
|
op.drop_table("snapshots")
|
|
op.drop_table("repositories")
|