-- 025-add-unique-constraint-beds-code.sql
-- Migration: Ensure unique `code` values in public.beds and add UNIQUE constraint.
--
-- Add UNIQUE constraint uq_beds_code on the code column.
BEGIN;

DO $$
BEGIN
	-- Only add the constraint if a relation with this name does not already exist
	IF to_regclass('public.uq_beds_code') IS NULL THEN
		ALTER TABLE public.beds
		ADD CONSTRAINT uq_beds_code UNIQUE (code);
	END IF;
END
$$;

COMMIT;