CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / TypeScript typecheck (push) Successful in 34s
CI & Build / Python tests (push) Successful in 2m1s
CI & Build / integration (push) Successful in 2m8s
CI & Build / Build & push image (push) Successful in 17s
Rows without a plugin version are skipped by every open-rate reader and are most of the table, so the correlated lookup runs on the rows recorded since 0133 only. Keeps the migration cheap on the live table, not just in CI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
"""a delivery of a rule the session had already opened counts as opened
|
|
|
|
Revision ID: 0135
|
|
Revises: 0134
|
|
Create Date: 2026-11-24
|
|
|
|
From now on a line for a rule the session has opened in the last six hours
|
|
is stamped opened as it is written (`rule_deliveries._read_already`). This
|
|
stamps the deliveries already recorded the same way, so the open rates, the
|
|
adherence readout and the weighing pass read one definition across old and
|
|
new rows: a rule read early in a session is not counted unread each time it
|
|
arrives again. The stamp is the delivery's own time. Only rows that carry a
|
|
plugin version are touched: every reader skips the others
|
|
(`rule_deliveries.REPORTS_OPENS`), and they are most of the table, so the
|
|
lookup runs on the few rows recorded since 0133 rather than on all of them.
|
|
Not reversible: the downgrade leaves the stamps, which the earlier code reads
|
|
as ordinary opens.
|
|
"""
|
|
from alembic import op
|
|
|
|
revision = "0135"
|
|
down_revision = "0134"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.execute(
|
|
"""
|
|
UPDATE rule_deliveries d
|
|
SET opened_at = d.delivered_at
|
|
WHERE d.opened_at IS NULL
|
|
AND d.plugin IS NOT NULL
|
|
AND EXISTS (
|
|
SELECT 1 FROM rule_deliveries e
|
|
WHERE e.user_id = d.user_id
|
|
AND e.session_id = d.session_id
|
|
AND e.rule_id = d.rule_id
|
|
AND e.opened_at IS NOT NULL
|
|
AND e.opened_at <= d.delivered_at
|
|
AND e.opened_at >= d.delivered_at - INTERVAL '6 hours'
|
|
)
|
|
"""
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
pass
|