Files
g0v0-server/migrations/versions/4f46c43d8601_notification_add_notification.py
2025-08-22 08:21:52 +00:00

129 lines
4.3 KiB
Python

"""notification: add notification
Revision ID: 4f46c43d8601
Revises: 2fcfc28846c1
Create Date: 2025-08-21 07:03:45.813547
"""
from __future__ import annotations
from collections.abc import Sequence
from alembic import op
import sqlalchemy as sa
import sqlmodel
# revision identifiers, used by Alembic.
revision: str = "4f46c43d8601"
down_revision: str | Sequence[str] | None = "2fcfc28846c1"
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(
"notifications",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column(
"name",
sa.Enum(
"BEATMAP_OWNER_CHANGE",
"BEATMAPSET_DISCUSSION_LOCK",
"BEATMAPSET_DISCUSSION_POST_NEW",
"BEATMAPSET_DISCUSSION_QUALIFIED_PROBLEM",
"BEATMAPSET_DISCUSSION_REVIEW_NEW",
"BEATMAPSET_DISCUSSION_UNLOCK",
"BEATMAPSET_DISQUALIFY",
"BEATMAPSET_LOVE",
"BEATMAPSET_NOMINATE",
"BEATMAPSET_QUALIFY",
"BEATMAPSET_RANK",
"BEATMAPSET_REMOVE_FROM_LOVED",
"BEATMAPSET_RESET_NOMINATIONS",
"CHANNEL_ANNOUNCEMENT",
"CHANNEL_MESSAGE",
"CHANNEL_TEAM",
"COMMENT_NEW",
"FORUM_TOPIC_REPLY",
"TEAM_APPLICATION_ACCEPT",
"TEAM_APPLICATION_REJECT",
"TEAM_APPLICATION_STORE",
"USER_ACHIEVEMENT_UNLOCK",
"USER_BEATMAPSET_NEW",
"USER_BEATMAPSET_REVIVE",
name="notificationname",
),
nullable=False,
),
sa.Column("category", sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=True),
sa.Column("object_type", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column("object_id", sa.BigInteger(), nullable=True),
sa.Column("source_user_id", sa.Integer(), nullable=False),
sa.Column("details", sa.JSON(), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f("ix_notifications_category"), "notifications", ["category"], unique=False)
op.create_index(op.f("ix_notifications_id"), "notifications", ["id"], unique=False)
op.create_index(op.f("ix_notifications_name"), "notifications", ["name"], unique=False)
op.create_index(op.f("ix_notifications_object_id"), "notifications", ["object_id"], unique=False)
op.create_index(
op.f("ix_notifications_object_type"),
"notifications",
["object_type"],
unique=False,
)
op.create_index(
op.f("ix_notifications_source_user_id"),
"notifications",
["source_user_id"],
unique=False,
)
op.create_table(
"user_notifications",
sa.Column("id", sa.BigInteger(), nullable=False),
sa.Column("notification_id", sa.Integer(), nullable=False),
sa.Column("user_id", sa.BigInteger(), nullable=True),
sa.Column("is_read", sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(
["notification_id"],
["notifications.id"],
),
sa.ForeignKeyConstraint(
["user_id"],
["lazer_users.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f("ix_user_notifications_id"), "user_notifications", ["id"], unique=False)
op.create_index(
op.f("ix_user_notifications_is_read"),
"user_notifications",
["is_read"],
unique=False,
)
op.create_index(
op.f("ix_user_notifications_notification_id"),
"user_notifications",
["notification_id"],
unique=False,
)
op.create_index(
op.f("ix_user_notifications_user_id"),
"user_notifications",
["user_id"],
unique=False,
)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("user_notifications")
op.drop_table("notifications")
# ### end Alembic commands ###