HR-ATS-Portal/backend/migrations/manual/021_job_post_requisition.sql

15 lines
713 B
SQL

-- 021_job_post_requisition.sql
-- Optional link from a job post to the Annexure A employee requisition it
-- was opened from (app.requisitions). Distinct from requisition_status, which
-- is the hiring lifecycle on job_posts. Applied at startup by
-- alembic_setup.run_manual_sql(). Needed because prod boots with
-- DB_AUTOGENERATE=false.
ALTER TABLE app.job_posts
ADD COLUMN IF NOT EXISTS requisition_id UUID REFERENCES app.requisitions(id) ON DELETE SET NULL;
-- Unique so one requisition maps to at most one job post. Postgres unique
-- indexes allow multiple NULLs, so unlinked job posts stay valid.
CREATE UNIQUE INDEX IF NOT EXISTS uq_job_posts_requisition_id
ON app.job_posts (requisition_id);