Files
RAGcore-Public/alembic/versions/0020_source_sync_schedule.py
T

48 lines
1.6 KiB
Python

"""How often a source should reconcile itself.
Until now a sync ran only when an operator asked for one, which made an index
that keeps step with its folder or repository something a person had to
remember rather than something the platform did. ``sync_interval_seconds``
is what the scheduler reads.
Nullable, with no server default, on purpose. NULL means *only when asked* --
exactly what every existing source already does -- so this migration changes
the behaviour of precisely nothing until an operator sets an interval.
Periodically reading someone's filesystem or repository is a decision, not
something an upgrade should quietly begin doing.
The partial index covers the scheduler's only query: the sources that have an
interval at all. In a deployment where most sources are manual, that index
stays a fraction of the table.
"""
from __future__ import annotations
import sqlalchemy as sa
from alembic import op
revision = "0020_source_sync_schedule"
down_revision = "0019_job_listing_index"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.add_column(
"sources",
sa.Column("sync_interval_seconds", sa.Integer(), nullable=True),
schema="content",
)
op.create_index(
"ix_content_sources_due",
"sources",
["last_sync_at"],
schema="content",
postgresql_where=sa.text("sync_interval_seconds IS NOT NULL"),
)
def downgrade() -> None:
op.drop_index("ix_content_sources_due", "sources", schema="content")
op.drop_column("sources", "sync_interval_seconds", schema="content")