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
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ def upgrade() -> None:
op.create_index("ix_posts_vendor", "posts", ["vendor"], unique=False)

# ── 3. Update voucher_posts view ──────────────────────────────────────────
# CREATE OR REPLACE VIEW cannot reorder view columns, so drop first.
op.execute(sa.text("DROP VIEW IF EXISTS voucher_posts"))
op.execute(
sa.text(
"""
CREATE OR REPLACE VIEW voucher_posts AS
CREATE VIEW voucher_posts AS
SELECT
p.id,
p.source_id,
Expand Down Expand Up @@ -112,10 +114,12 @@ def upgrade() -> None:


def downgrade() -> None:
# CREATE OR REPLACE VIEW cannot reorder view columns, so drop first.
op.execute(sa.text("DROP VIEW IF EXISTS voucher_posts"))
op.execute(
sa.text(
"""
CREATE OR REPLACE VIEW voucher_posts AS
CREATE VIEW voucher_posts AS
SELECT
p.id,
p.source_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Add missing created_at/updated_at to keywords and pipeline_lock

Revision ID: o9p8q7r6s5t4
Revises: m6n7o8p9q0r1
Create Date: 2026-08-15

The ``Base`` model declares ``created_at``/``updated_at`` on every mapped
table, but the ``keywords`` (g3b9c0d1e2f3) and ``pipeline_lock``
(e1c2d3a4b5f6) creation migrations omitted them. The ORM therefore emits
SELECTs referencing ``keywords.created_at`` / ``pipeline_lock.created_at``
which never existed, failing the scheduler with ``UndefinedColumnError``.
This migration backfills the missing columns to match the models.
"""

from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = "o9p8q7r6s5t4"
down_revision: Union[str, Sequence[str], None] = "m6n7o8p9q0r1"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
for table in ("keywords", "pipeline_lock"):
op.add_column(
table,
sa.Column(
"created_at",
sa.DateTime(),
nullable=False,
server_default=sa.func.now(),
),
)
op.add_column(
table,
sa.Column(
"updated_at",
sa.DateTime(),
nullable=False,
server_default=sa.func.now(),
),
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.


def downgrade() -> None:
for table in ("pipeline_lock", "keywords"):
op.drop_column(table, "updated_at")
op.drop_column(table, "created_at")
2 changes: 1 addition & 1 deletion tests/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

_VERSIONS_DIR = Path(__file__).resolve().parents[1] / "migrations" / "versions"

_EXPECTED_HEAD = "m6n7o8p9q0r1"
_EXPECTED_HEAD = "o9p8q7r6s5t4"

# Every model-backed table (views are excluded — voucher_posts is created via
# migrations as a view, not through Base.metadata.create_all).
Expand Down
Loading