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>
22 lines
948 B
SQL
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);
|