From 38dc4d28c85d30484fed72386b759444621ae168 Mon Sep 17 00:00:00 2001 From: Metrohan Date: Tue, 4 Aug 2026 00:10:19 +0300 Subject: [PATCH 1/2] fix(db): widen location and path columns to prevent varchar(255) overflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit events.location and pending_events.location -> Text (unbounded): scrapers pull full-address strings from some sources that exceed 255 chars. traffic_logs.path -> String(500): bots occasionally send very long URLs. PostgreSQL widens VARCHAR to TEXT with a metadata-only operation — no table rewrite, no row locks. Requires alembic upgrade head after deploy. Co-Authored-By: Claude Sonnet 4.6 --- ...9c0d1e2_widen_location_and_path_columns.py | 71 +++++++++++++++++++ app/models/event.py | 2 +- app/models/pending_event.py | 2 +- app/models/traffic_log.py | 2 +- 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 alembic/versions/f7a8b9c0d1e2_widen_location_and_path_columns.py diff --git a/alembic/versions/f7a8b9c0d1e2_widen_location_and_path_columns.py b/alembic/versions/f7a8b9c0d1e2_widen_location_and_path_columns.py new file mode 100644 index 0000000..17d9235 --- /dev/null +++ b/alembic/versions/f7a8b9c0d1e2_widen_location_and_path_columns.py @@ -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 = "e6f7a8b9c0d1" +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)", + ) diff --git a/app/models/event.py b/app/models/event.py index 7395320..6e53784 100644 --- a/app/models/event.py +++ b/app/models/event.py @@ -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)) diff --git a/app/models/pending_event.py b/app/models/pending_event.py index d0d3600..be2334a 100644 --- a/app/models/pending_event.py +++ b/app/models/pending_event.py @@ -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) diff --git a/app/models/traffic_log.py b/app/models/traffic_log.py index 60edef6..b355419 100644 --- a/app/models/traffic_log.py +++ b/app/models/traffic_log.py @@ -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) From 57e84b71bac4d7f6084208c13265f7c4e3048edd Mon Sep 17 00:00:00 2001 From: Metrohan Date: Tue, 4 Aug 2026 00:18:47 +0300 Subject: [PATCH 2/2] fix(alembic): set correct down_revision for varchar-overflow migration f7a8b9c0d1e2 was chaining from e6f7a8b9c0d1 but f1a2b3c4d5e6 (add_event_thumbnail_url) had already advanced the head from that revision, creating two heads. Point down_revision at f1a2b3c4d5e6. Co-Authored-By: Claude Sonnet 4.6 --- .../versions/f7a8b9c0d1e2_widen_location_and_path_columns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alembic/versions/f7a8b9c0d1e2_widen_location_and_path_columns.py b/alembic/versions/f7a8b9c0d1e2_widen_location_and_path_columns.py index 17d9235..041ed42 100644 --- a/alembic/versions/f7a8b9c0d1e2_widen_location_and_path_columns.py +++ b/alembic/versions/f7a8b9c0d1e2_widen_location_and_path_columns.py @@ -15,7 +15,7 @@ import sqlalchemy as sa revision = "f7a8b9c0d1e2" -down_revision = "e6f7a8b9c0d1" +down_revision = "f1a2b3c4d5e6" branch_labels = None depends_on = None