57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
"""0005 snapshots
|
|
|
|
Revision ID: 0005
|
|
Revises: 0004
|
|
Create Date: 2026-04-07
|
|
"""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
revision = "0005"
|
|
down_revision = "0004"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Content-addressed storage: one row per unique file content
|
|
op.create_table(
|
|
"snapshot_contents",
|
|
sa.Column("sha256", sa.String(64), primary_key=True),
|
|
sa.Column("content", sa.Text(), nullable=False),
|
|
sa.Column("size", sa.Integer(), nullable=False),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
|
)
|
|
|
|
# Each snapshot capture event points to a content row
|
|
op.create_table(
|
|
"config_snapshots",
|
|
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
|
sa.Column(
|
|
"device_id",
|
|
sa.Integer(),
|
|
sa.ForeignKey("devices.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
),
|
|
sa.Column(
|
|
"sha256",
|
|
sa.String(64),
|
|
sa.ForeignKey("snapshot_contents.sha256"),
|
|
nullable=False,
|
|
),
|
|
sa.Column("label", sa.String(255), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index(
|
|
"ix_config_snapshots_device_created",
|
|
"config_snapshots",
|
|
["device_id", "created_at"],
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_config_snapshots_device_created", table_name="config_snapshots")
|
|
op.drop_table("config_snapshots")
|
|
op.drop_table("snapshot_contents")
|