feat: backdated reported date for old active tickets
Wahab can now enter historical tickets that keep their true reported date: - Add nullable tickets.reported_at (DateTime) via alembic d5e0f2a1c3b4; backfill existing rows from created_at so nothing shows empty. - TicketCreate.reported_at (optional) is persisted by create_ticket and defaults to now when omitted, so existing create behavior is unchanged. - New-issue form gains a 'Reported Date' date picker (defaults to today, past dates allowed, future blocked) and sends reported_at in the payload. - List and detail pages show 'Reported' next to 'Created' (date-only, labeled) so backdated tickets are obvious; SLA deadline is unchanged and still runs from creation time so backfilling never instantly breaches. - Tests: backdated create persists + is exposed on list/detail; omitted reported_at defaults to now; SLA window unchanged; full datetime round trip.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
"""tickets.reported_at column — original reported date for backdated tickets
|
||||
|
||||
Revision ID: d5e0f2a1c3b4
|
||||
Revises: c4e8f1a2d3b4
|
||||
Create Date: 2026-08-03 00:00:00.000000
|
||||
|
||||
Backdated-ticket support (Wahab demo): one schema change.
|
||||
|
||||
* Add ``tickets.reported_at`` (nullable DateTime) so historical/backfilled
|
||||
tickets keep their true report date instead of inheriting today's
|
||||
``created_at``.
|
||||
* Backfill existing rows with their ``created_at`` value so no ticket shows
|
||||
an empty reported date after the upgrade. The service layer also defaults
|
||||
new tickets without a ``reported_at`` to now, so the column is effectively
|
||||
always populated from here on.
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'd5e0f2a1c3b4'
|
||||
down_revision: Union[str, Sequence[str], None] = 'c4e8f1a2d3b4'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Add tickets.reported_at (nullable) and backfill from created_at."""
|
||||
op.add_column(
|
||||
'tickets',
|
||||
sa.Column(
|
||||
'reported_at',
|
||||
sa.DateTime(),
|
||||
nullable=True,
|
||||
comment='Original reported date; backdated/backfilled tickets keep their true report date',
|
||||
),
|
||||
)
|
||||
# Backfill: every existing ticket was reported when it was created.
|
||||
op.execute('UPDATE tickets SET reported_at = created_at WHERE reported_at IS NULL')
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Drop tickets.reported_at."""
|
||||
op.drop_column('tickets', 'reported_at')
|
||||
Reference in New Issue
Block a user