63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
|
|
"""Add forgejo_commit_activity table for per-repository per-day commit counts.
|
||
|
|
|
||
|
|
Revision ID: b1c2d3e4f5a6
|
||
|
|
Revises: a1b2c3d4e5f9, a3c5e7f9b1d2
|
||
|
|
Create Date: 2026-05-24 00:00:00.000000
|
||
|
|
|
||
|
|
"""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import sqlalchemy as sa
|
||
|
|
from alembic import op
|
||
|
|
|
||
|
|
revision = "b1c2d3e4f5a6"
|
||
|
|
down_revision = ("a1b2c3d4e5f9", "a3c5e7f9b1d2")
|
||
|
|
branch_labels = None
|
||
|
|
depends_on = None
|
||
|
|
|
||
|
|
|
||
|
|
def upgrade() -> None:
|
||
|
|
op.create_table(
|
||
|
|
"forgejo_commit_activity",
|
||
|
|
sa.Column("id", sa.Uuid(), nullable=False),
|
||
|
|
sa.Column("organization_id", sa.Uuid(), nullable=False),
|
||
|
|
sa.Column("repository_id", sa.Uuid(), nullable=False),
|
||
|
|
sa.Column("date", sa.Date(), nullable=False),
|
||
|
|
sa.Column("commit_count", sa.Integer(), nullable=False, server_default="0"),
|
||
|
|
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||
|
|
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||
|
|
sa.ForeignKeyConstraint(["organization_id"], ["organizations.id"]),
|
||
|
|
sa.ForeignKeyConstraint(["repository_id"], ["forgejo_repositories.id"]),
|
||
|
|
sa.PrimaryKeyConstraint("id"),
|
||
|
|
)
|
||
|
|
op.create_index(
|
||
|
|
"ix_forgejo_commit_activity_organization_id",
|
||
|
|
"forgejo_commit_activity",
|
||
|
|
["organization_id"],
|
||
|
|
)
|
||
|
|
op.create_index(
|
||
|
|
"ix_forgejo_commit_activity_repository_id",
|
||
|
|
"forgejo_commit_activity",
|
||
|
|
["repository_id"],
|
||
|
|
)
|
||
|
|
op.create_index(
|
||
|
|
"ix_forgejo_commit_activity_date",
|
||
|
|
"forgejo_commit_activity",
|
||
|
|
["date"],
|
||
|
|
)
|
||
|
|
op.create_index(
|
||
|
|
"ix_forgejo_commit_activity_repo_date",
|
||
|
|
"forgejo_commit_activity",
|
||
|
|
["repository_id", "date"],
|
||
|
|
unique=True,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def downgrade() -> None:
|
||
|
|
op.drop_index("ix_forgejo_commit_activity_repo_date", "forgejo_commit_activity")
|
||
|
|
op.drop_index("ix_forgejo_commit_activity_date", "forgejo_commit_activity")
|
||
|
|
op.drop_index("ix_forgejo_commit_activity_repository_id", "forgejo_commit_activity")
|
||
|
|
op.drop_index("ix_forgejo_commit_activity_organization_id", "forgejo_commit_activity")
|
||
|
|
op.drop_table("forgejo_commit_activity")
|