"""project_visits: when each person last looked at a board

Revision ID: a7c04e1b93d5
Revises: f3b8d24e07a1
Create Date: 2026-09-01

The engagement guarantees a second visit — the homepage is decided, then the
remaining pages are designed against it — so "what is new?" is the first
question a returning client has.
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = 'a7c04e1b93d5'
down_revision: Union[str, Sequence[str], None] = 'f3b8d24e07a1'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.create_table(
        'project_visits',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('instance_id', sa.String(length=64), nullable=False),
        sa.Column('username', sa.String(length=64), nullable=False),
        sa.Column('last_seen_at', sa.DateTime(timezone=True), nullable=False),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('instance_id', 'username', name='uq_project_visit_who'),
    )
    op.create_index(op.f('ix_project_visits_instance_id'), 'project_visits',
                    ['instance_id'], unique=False)
    op.create_index(op.f('ix_project_visits_username'), 'project_visits',
                    ['username'], unique=False)


def downgrade() -> None:
    op.drop_index(op.f('ix_project_visits_username'), table_name='project_visits')
    op.drop_index(op.f('ix_project_visits_instance_id'), table_name='project_visits')
    op.drop_table('project_visits')
