"""portfolio_comments table Revision ID: 20260410_0009 Revises: 20260403_0008 Create Date: 2026-04-10 00:00:00 """ from __future__ import annotations import sqlalchemy as sa from alembic import op revision = "20260410_0009" down_revision = "20260403_0008" branch_labels = None depends_on = None def upgrade() -> None: # `ensure_schema()` can create this table ahead of Alembic on already-running # environments, so this migration must be safe to re-apply. op.execute( """ CREATE TABLE IF NOT EXISTS portfolio_comments ( id TEXT NOT NULL, portfolio_id TEXT NOT NULL, content TEXT NOT NULL, created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL, updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL, PRIMARY KEY (id) ) """ ) op.execute( """ CREATE INDEX IF NOT EXISTS idx_portfolio_comments_portfolio_created ON portfolio_comments (portfolio_id, created_at DESC) """ ) def downgrade() -> None: op.execute("DROP INDEX IF EXISTS idx_portfolio_comments_portfolio_created") op.execute("DROP TABLE IF EXISTS portfolio_comments")