Files
warmbly/internal/infrastructure/db/migrations/000025_sequence_position.up.sql
T

11 lines
362 B
SQL

ALTER TABLE sequences ADD COLUMN IF NOT EXISTS position INT NOT NULL DEFAULT 0;
-- Backfill position based on existing creation order per campaign
WITH ranked AS (
SELECT id, ROW_NUMBER() OVER (PARTITION BY campaign_id ORDER BY created_at ASC) AS rn
FROM sequences
)
UPDATE sequences SET position = ranked.rn
FROM ranked
WHERE sequences.id = ranked.id;