"""comment_revisions — an edit cannot rewrite the record silently

Revision ID: d18b3c6f9a72
Revises: c9e51d7ab204
Create Date: 2026-09-01

Anyone can fix their own mistake; nobody can make the earlier wording vanish.
"you said X" / "no, I said Y" is the dispute this whole tool exists to prevent.
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = 'd18b3c6f9a72'
down_revision: Union[str, Sequence[str], None] = 'c9e51d7ab204'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.create_table(
        'comment_revisions',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('comment_id', sa.Integer(), nullable=False),
        sa.Column('body_md', sa.Text(), nullable=False),
        sa.Column('replaced_at', sa.DateTime(timezone=True), nullable=False),
        sa.ForeignKeyConstraint(['comment_id'], ['comment.id'], ondelete='CASCADE'),
        sa.PrimaryKeyConstraint('id'),
    )
    op.create_index(op.f('ix_comment_revisions_comment_id'), 'comment_revisions',
                    ['comment_id'], unique=False)


def downgrade() -> None:
    op.drop_index(op.f('ix_comment_revisions_comment_id'),
                  table_name='comment_revisions')
    op.drop_table('comment_revisions')
