Files
QuoteForge/migrations/028_add_line_no_to_configurations.sql

19 lines
579 B
SQL

ALTER TABLE qt_configurations
ADD COLUMN IF NOT EXISTS line_no INT NULL AFTER only_in_stock;
UPDATE qt_configurations q
JOIN (
SELECT
id,
ROW_NUMBER() OVER (
PARTITION BY COALESCE(NULLIF(TRIM(project_uuid), ''), '__NO_PROJECT__')
ORDER BY created_at ASC, id ASC
) AS rn
FROM qt_configurations
WHERE line_no IS NULL OR line_no <= 0
) ranked ON ranked.id = q.id
SET q.line_no = ranked.rn * 10;
ALTER TABLE qt_configurations
ADD INDEX IF NOT EXISTS idx_qt_configurations_project_line_no (project_uuid, line_no);