46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
"""add pinned messages table"""
|
|
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
revision: str = "c9c71d04f0a1"
|
|
down_revision: Union[str, None] = "e3c1e0b5b4a7"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
TABLE_NAME = "pinned_messages"
|
|
|
|
|
|
def _table_exists(inspector: sa.Inspector) -> bool:
|
|
return TABLE_NAME in inspector.get_table_names()
|
|
|
|
|
|
def upgrade() -> None:
|
|
bind = op.get_bind()
|
|
inspector = sa.inspect(bind)
|
|
|
|
if _table_exists(inspector):
|
|
return
|
|
|
|
op.create_table(
|
|
TABLE_NAME,
|
|
sa.Column("id", sa.Integer(), primary_key=True, index=True),
|
|
sa.Column("content", sa.Text(), nullable=False),
|
|
sa.Column("is_active", sa.Boolean(), default=True),
|
|
sa.Column("created_by", sa.Integer(), sa.ForeignKey("users.id", ondelete="SET NULL"), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(), server_default=sa.func.now()),
|
|
sa.Column("updated_at", sa.DateTime(), server_default=sa.func.now(), onupdate=sa.func.now()),
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
bind = op.get_bind()
|
|
inspector = sa.inspect(bind)
|
|
|
|
if _table_exists(inspector):
|
|
op.drop_table(TABLE_NAME)
|