nxtgauge-backend-rust/crates/db/migrations/20260327100000_designations_management_fields.up.sql
Ashwin Kumar 3b28d9fd36 feat: add designation management CRUD backend
Full CRUD handler for designations with department JOIN, employee count,
level/can_manage_team/can_approve fields, and migration to extend the
minimal designations table with all management columns.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-27 19:20:55 +01:00

22 lines
948 B
SQL

ALTER TABLE designations
ADD COLUMN IF NOT EXISTS code VARCHAR(64),
ADD COLUMN IF NOT EXISTS department_id UUID REFERENCES departments(id) ON DELETE SET NULL,
ADD COLUMN IF NOT EXISTS description TEXT,
ADD COLUMN IF NOT EXISTS level VARCHAR(100),
ADD COLUMN IF NOT EXISTS can_manage_team BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN IF NOT EXISTS can_approve BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN IF NOT EXISTS is_active BOOLEAN NOT NULL DEFAULT true,
ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW();
UPDATE designations
SET updated_at = COALESCE(updated_at, created_at, NOW());
CREATE UNIQUE INDEX IF NOT EXISTS idx_designations_code_unique
ON designations (LOWER(code))
WHERE code IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_designations_is_active
ON designations (is_active);
CREATE INDEX IF NOT EXISTS idx_designations_department_id
ON designations (department_id);