fix(coderd/database): ensure task name uniqueness (#20236)

This change ensures task names are unique per user the same way we do
for workspaces. This ensures we don't create tasks that are impossible
to start due to another task being named the same creating a workspace
name conflict.

Updates coder/internal#948
Supersedes coder/coder#20212
This commit is contained in:
Mathias Fredriksson
2025-10-13 12:42:38 +03:00
committed by GitHub
parent 952c69f412
commit 5dc57da6b4
5 changed files with 90 additions and 0 deletions
@@ -0,0 +1 @@
DROP INDEX IF EXISTS tasks_owner_id_name_unique_idx;
@@ -0,0 +1,2 @@
CREATE UNIQUE INDEX IF NOT EXISTS tasks_owner_id_name_unique_idx ON tasks (owner_id, LOWER(name)) WHERE deleted_at IS NULL;
COMMENT ON INDEX tasks_owner_id_name_unique_idx IS 'Index to ensure uniqueness for task owner/name';