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
71 changes: 71 additions & 0 deletions alembic/versions/f7a8b9c0d1e2_widen_location_and_path_columns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""widen location and path columns to prevent varchar(255) overflow

Revision ID: f7a8b9c0d1e2
Revises: e6f7a8b9c0d1
Create Date: 2026-08-04 00:00:00.000000

events.location and pending_events.location overflow when scrapers pull
full-address strings from new sources. traffic_logs.path overflows when
bots hit the site with excessively long URLs. In PostgreSQL, widening
VARCHAR to TEXT (or larger VARCHAR) is a metadata-only operation — no
table rewrite, no locks beyond an ACCESS EXCLUSIVE for the catalog update.
"""

from alembic import op
import sqlalchemy as sa

revision = "f7a8b9c0d1e2"
down_revision = "f1a2b3c4d5e6"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.alter_column(
"events",
"location",
existing_type=sa.String(length=255),
type_=sa.Text(),
existing_nullable=True,
)
op.alter_column(
"pending_events",
"location",
existing_type=sa.String(length=255),
type_=sa.Text(),
existing_nullable=True,
)
op.alter_column(
"traffic_logs",
"path",
existing_type=sa.String(length=255),
type_=sa.String(length=500),
existing_nullable=False,
)


def downgrade() -> None:
op.alter_column(
"traffic_logs",
"path",
existing_type=sa.String(length=500),
type_=sa.String(length=255),
existing_nullable=False,
postgresql_using="left(path, 255)",
)
op.alter_column(
"pending_events",
"location",
existing_type=sa.Text(),
type_=sa.String(length=255),
existing_nullable=True,
postgresql_using="left(location, 255)",
)
op.alter_column(
"events",
"location",
existing_type=sa.Text(),
type_=sa.String(length=255),
existing_nullable=True,
postgresql_using="left(location, 255)",
)
2 changes: 1 addition & 1 deletion app/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Event(Base):
description = Column(Text)
date = Column(DateTime)
application_deadline = Column(DateTime)
location = Column(String(255))
location = Column(Text)
url = Column(String(500), unique=True, nullable=False, index=True)
image_url = Column(String(500))
thumbnail_url = Column(String(500))
Expand Down
2 changes: 1 addition & 1 deletion app/models/pending_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PendingEvent(Base):
title = Column(String(500), nullable=False)
description = Column(Text)
date = Column(DateTime)
location = Column(String(255))
location = Column(Text)
url = Column(String(500), nullable=False)
image_url = Column(String(500))
source = Column(String(100), nullable=False)
Expand Down
2 changes: 1 addition & 1 deletion app/models/traffic_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TrafficLog(Base):
__tablename__ = "traffic_logs"

id = Column(Integer, primary_key=True, index=True)
path = Column(String(255), nullable=False)
path = Column(String(500), nullable=False)
method = Column(String(10), nullable=False)
ip_address = Column(String(45), nullable=True)
user_agent = Column(Text, nullable=True)
Expand Down
Loading