-- Visits tracking table
-- Postgres dialect

create table visits (
    id serial primary key,
    user_id integer references users(id) on delete set null,
    proposal_id integer not null,
    path text not null,
    method text not null,
    query_string text,
    status_code integer,
    ip_address text,
    user_agent text,
    referrer text,
    session_id text,
    request_id text,
    visited_at timestamptz not null default now(),
    created_at timestamptz not null default now(),
    updated_at timestamptz not null default now()
);

-- Helpful indexes for analytics and lookups
create index idx_visits_visited_at on visits(visited_at);
create index idx_visits_user_id on visits(user_id);
create index idx_visits_proposal_id on visits(proposal_id);
create index idx_visits_path on visits(path);
create index idx_visits_method on visits(method);
