Files
g0v0-server/migrations/versions/2025-08-11_aa582c13f905_count_add_replays_watched_counts.py

85 lines
2.4 KiB
Python

"""count: add replays_watched_counts
Revision ID: aa582c13f905
Revises: 319e5f841dcf
Create Date: 2025-08-11 08:03:33.739398
"""
from __future__ import annotations
from collections.abc import Sequence
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = "aa582c13f905"
down_revision: str | Sequence[str] | None = "319e5f841dcf"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"replays_watched_counts",
sa.Column("year", sa.Integer(), nullable=False),
sa.Column("month", sa.Integer(), nullable=False),
sa.Column("count", sa.Integer(), nullable=False),
sa.Column("id", sa.BigInteger(), autoincrement=True, nullable=False),
sa.Column("user_id", sa.BigInteger(), nullable=True),
sa.ForeignKeyConstraint(
["user_id"],
["lazer_users.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_replays_watched_counts_month"),
"replays_watched_counts",
["month"],
unique=False,
)
op.create_index(
op.f("ix_replays_watched_counts_user_id"),
"replays_watched_counts",
["user_id"],
unique=False,
)
op.create_index(
op.f("ix_replays_watched_counts_year"),
"replays_watched_counts",
["year"],
unique=False,
)
op.alter_column(
"monthly_playcounts",
"playcount",
new_column_name="count",
type_=sa.Integer(),
)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column(
"monthly_playcounts",
"count",
new_column_name="playcount",
type_=sa.Integer(),
)
op.drop_constraint(
"replays_watched_counts_ibfk_1",
"replays_watched_counts",
type_="foreignkey",
)
op.drop_index(op.f("ix_replays_watched_counts_year"), table_name="replays_watched_counts")
op.drop_index(op.f("ix_replays_watched_counts_user_id"), table_name="replays_watched_counts")
op.drop_index(op.f("ix_replays_watched_counts_month"), table_name="replays_watched_counts")
op.drop_table("replays_watched_counts")
# ### end Alembic commands ###