Skip to content

Commit 2f56b64

Browse files
committed
add offliner definition version to schedule history entry
1 parent 1b30313 commit 2f56b64

File tree

6 files changed

+67
-0
lines changed

6 files changed

+67
-0
lines changed

backend/src/zimfarm_backend/common/schemas/orms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ class ScheduleHistorySchema(BaseModel):
290290
periodicity: str
291291
context: str
292292
archived: bool
293+
offliner_definition_version: str | None = None
293294
# entries are serialized as dict[str, Any] instead of ScheduleConfigSchema
294295
# because the entry is possibly outdated and would fail validation as the
295296
# offliner schema evolves

backend/src/zimfarm_backend/db/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ class ScheduleHistory(Base):
310310
language_code: Mapped[str]
311311
tags: Mapped[list[str]]
312312
periodicity: Mapped[str]
313+
offliner_definition_version: Mapped[str | None]
313314
context: Mapped[str] = mapped_column(default="", server_default="")
314315
archived: Mapped[bool] = mapped_column(default=False, server_default=false())
315316

backend/src/zimfarm_backend/db/schedule.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ def create_schedule(
399399
tags=schedule.tags,
400400
periodicity=schedule.periodicity,
401401
context=schedule.context,
402+
offliner_definition_version=offliner_definition.version,
402403
)
403404
schedule.history_entries.append(history_entry)
404405

@@ -531,6 +532,7 @@ def toggle_archive_status(
531532
periodicity=schedule.periodicity,
532533
context=schedule.context,
533534
archived=schedule.archived,
535+
offliner_definition_version=schedule.offliner_definition.version,
534536
)
535537
schedule.history_entries.append(history_entry)
536538
session.add(schedule)
@@ -599,6 +601,7 @@ def update_schedule(
599601
periodicity=schedule.periodicity,
600602
context=schedule.context,
601603
archived=schedule.archived,
604+
offliner_definition_version=offliner_definition.version,
602605
)
603606
schedule.history_entries.append(history_entry)
604607

@@ -642,6 +645,7 @@ def create_schedule_history_schema(
642645
context=history_entry.context,
643646
config=history_entry.config,
644647
archived=history_entry.archived,
648+
offliner_definition_version=history_entry.offliner_definition_version,
645649
)
646650

647651

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""store offliner definition version in schedule history
2+
3+
Revision ID: 8b0210f9d9ab
4+
Revises: b298a5831211
5+
Create Date: 2025-11-25 09:57:58.062755
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
from sqlalchemy.orm import Session
12+
13+
# revision identifiers, used by Alembic.
14+
revision = "8b0210f9d9ab"
15+
down_revision = "b298a5831211"
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade() -> None:
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
op.add_column(
23+
"schedule_history",
24+
sa.Column("offliner_definition_version", sa.String(), nullable=True),
25+
)
26+
# ### end Alembic commands ###
27+
28+
# Populate offliner_definition_version for latest schedule_history of each schedule
29+
bind = op.get_bind()
30+
session = Session(bind=bind)
31+
session.execute(
32+
sa.text(
33+
"""
34+
WITH latest AS (
35+
SELECT DISTINCT ON (schedule_id)
36+
id AS history_id,
37+
schedule_id
38+
FROM schedule_history
39+
ORDER BY schedule_id, created_at DESC
40+
)
41+
42+
UPDATE schedule_history AS sh
43+
SET offliner_definition_version = od.version
44+
FROM schedule AS s
45+
JOIN offliner_definition AS od
46+
ON s.offliner_definition_id = od.id
47+
JOIN latest
48+
ON latest.schedule_id = s.id
49+
WHERE sh.schedule_id = s.id
50+
AND sh.id = latest.history_id
51+
"""
52+
)
53+
)
54+
55+
56+
def downgrade() -> None:
57+
# ### commands auto generated by Alembic - please adjust! ###
58+
op.drop_column("schedule_history", "offliner_definition_version")
59+
# ### end Alembic commands ###

backend/tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@ def _create_schedule(
944944
tags=schedule.tags,
945945
periodicity=schedule.periodicity,
946946
context=schedule.context,
947+
offliner_definition_version=mwoffliner_definition.version,
947948
)
948949
schedule.history_entries.append(history_entry)
949950

frontend-ui/src/types/schedule.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export interface BaseScheduleHistorySchema {
3333
periodicity: string
3434
context: string
3535
archived: boolean
36+
offliner_definition_version?: string
3637
}
3738

3839
export interface ScheduleHistorySchema extends BaseScheduleHistorySchema {

0 commit comments

Comments
 (0)