"""Moderated discussion comments. Revision ID: f2a1c9d4e801 Revises: e8d4f1a27c93 """ from alembic import op revision = "f2a1c9d4e801" down_revision = "e8d4f1a27c93" branch_labels = None depends_on = None def upgrade(): op.execute(""" CREATE TABLE IF NOT EXISTS comments ( id SERIAL PRIMARY KEY, article_id INTEGER REFERENCES articles(id) ON DELETE CASCADE, question_id INTEGER REFERENCES questions(id) ON DELETE CASCADE, user_id INTEGER REFERENCES users(id) ON DELETE SET NULL, content TEXT NOT NULL, status VARCHAR(20) NOT NULL DEFAULT 'pending', created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP )""") op.execute("CREATE INDEX IF NOT EXISTS ix_comments_id ON comments (id)") op.execute("CREATE INDEX IF NOT EXISTS ix_comments_article_id ON comments (article_id)") op.execute("CREATE INDEX IF NOT EXISTS ix_comments_question_id ON comments (question_id)") def downgrade(): op.execute("DROP TABLE IF EXISTS comments")