Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions alembic/versions/05c3975bc951_create_fresh_paper_review_table.py

This file was deleted.

57 changes: 57 additions & 0 deletions alembic/versions/recreate_paper_review_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Recreate paper_review table with correct structure

Revision ID: abc123456789
Revises: d61647327666
Create Date: 2025-01-28 17:30:00.000000

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = 'abc123456789'
down_revision = 'd61647327666'
branch_labels = None
depends_on = None


def upgrade() -> None:
# Drop the existing paper_review table
op.drop_index('idx_paper_review_paper_id', table_name='paper_review')
op.drop_table('paper_review')

# Create the new paper_review table with the desired structure
op.create_table('paper_review',
sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
sa.Column('aixiv_id', sa.String(length=128), nullable=False),
sa.Column('version', sa.String(length=45), nullable=False),
sa.Column('review_results', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
sa.Column('agent_type', sa.SmallInteger(), server_default=sa.text('1'), nullable=False),
sa.Column('doc_type', sa.SmallInteger(), server_default=sa.text('1'), nullable=False),
sa.Column('create_time', sa.TIMESTAMP(), server_default=sa.text('now()'), nullable=False),
sa.Column('like_count', sa.Integer(), server_default=sa.text('0'), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index('idx_paper_review_aixiv_id_create_time', 'paper_review', ['aixiv_id', 'create_time'], unique=False)


def downgrade() -> None:
# Drop the new paper_review table
op.drop_index('idx_paper_review_aixiv_id_create_time', table_name='paper_review')
op.drop_table('paper_review')

# Recreate the old paper_review table structure
op.create_table('paper_review',
sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
sa.Column('paper_id', sa.String(length=128), nullable=False),
sa.Column('review', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
sa.Column('status', sa.Integer(), server_default=sa.text('2'), nullable=False),
sa.Column('create_time', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('ip', sa.String(length=45), nullable=True),
sa.Column('like_count', sa.Integer(), server_default=sa.text('0'), nullable=False),
sa.Column('reviewer', sa.String(length=128), server_default=sa.text("'Anonymous Reviewer'"), nullable=False),
sa.Column('user_id', sa.String(length=64), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index('idx_paper_review_paper_id', 'paper_review', ['paper_id'], unique=False)
69 changes: 69 additions & 0 deletions check_all_records.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import os
import psycopg2
import json

def check_all_records():
conn = psycopg2.connect(os.environ['DATABASE_URL'])
cur = conn.cursor()

# Get all tables
cur.execute("SELECT tablename FROM pg_tables WHERE schemaname = 'public'")
tables = [row[0] for row in cur.fetchall()]

print('All Records in Database:')
print('=' * 60)

for table in sorted(tables):
print(f'\nTable: {table}')
print('-' * 40)

# Get column names first
cur.execute("""
SELECT column_name
FROM information_schema.columns
WHERE table_name = %s
ORDER BY ordinal_position
""", (table,))

columns = [row[0] for row in cur.fetchall()]

# Get all records
cur.execute(f"SELECT * FROM {table}")
records = cur.fetchall()

if not records:
print(" (No records)")
continue

print(f" Found {len(records)} record(s)")
print()

# Print column headers
print(" " + " | ".join(f"{col:<15}" for col in columns))
print(" " + "-" * (16 * len(columns) + len(columns) - 1))

# Print each record
for i, record in enumerate(records, 1):
values = []
for val in record:
if val is None:
values.append("NULL")
elif isinstance(val, dict):
values.append(json.dumps(val)[:50] + "..." if len(json.dumps(val)) > 50 else json.dumps(val))
else:
str_val = str(val)
values.append(str_val[:50] + "..." if len(str_val) > 50 else str_val)

print(f" " + " | ".join(f"{val:<15}" for val in values))

# Limit output for large tables
if i >= 10:
print(f" ... ({len(records) - 10} more records)")
break

print()

conn.close()

if __name__ == "__main__":
check_all_records()
43 changes: 43 additions & 0 deletions check_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import psycopg2

def check_schema():
conn = psycopg2.connect(os.environ['DATABASE_URL'])
cur = conn.cursor()

# Get all tables
cur.execute("SELECT tablename FROM pg_tables WHERE schemaname = 'public'")
tables = [row[0] for row in cur.fetchall()]

print('Database Schema:')
print('=' * 50)

for table in sorted(tables):
print(f'\nTable: {table}')
print('-' * 30)

# Get column information
cur.execute("""
SELECT
column_name,
data_type,
character_maximum_length,
is_nullable,
column_default
FROM information_schema.columns
WHERE table_name = %s
ORDER BY ordinal_position
""", (table,))

columns = cur.fetchall()
for col in columns:
name, dtype, max_len, nullable, default = col
length_str = f'({max_len})' if max_len else ''
nullable_str = 'NULL' if nullable == 'YES' else 'NOT NULL'
default_str = f' DEFAULT {default}' if default else ''
print(f' {name}: {dtype}{length_str} {nullable_str}{default_str}')

conn.close()

if __name__ == "__main__":
check_schema()