Files
friendolls/src-tauri/migrations/20260831000000_add_remote_priority.sql
T
2026-08-31 14:45:48 +08:00

15 lines
506 B
SQL

ALTER TABLE remotes ADD COLUMN priority INTEGER NOT NULL DEFAULT 0;
UPDATE remotes AS remote
SET priority = (
SELECT COUNT(*)
FROM remotes AS preceding
WHERE COALESCE(preceding.name, preceding.address) COLLATE NOCASE
< COALESCE(remote.name, remote.address) COLLATE NOCASE
OR (
COALESCE(preceding.name, preceding.address) COLLATE NOCASE
= COALESCE(remote.name, remote.address) COLLATE NOCASE
AND preceding.id < remote.id
)
);