-- Add column only if it doesn't exist DO $$ BEGIN IF NOT EXISTS ( SELECT 1 FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'servizio_annunci' AND column_name = 'servizio_annunci_id' ) THEN ALTER TABLE public.servizio_annunci ADD COLUMN servizio_annunci_id serial NOT NULL; END IF; END $$; -- Add primary key only if it doesn't exist DO $$ BEGIN IF NOT EXISTS ( SELECT 1 FROM pg_constraint WHERE conname = 'servizio_annunci_pkey' AND conrelid = 'public.servizio_annunci'::regclass ) THEN ALTER TABLE public.servizio_annunci ADD PRIMARY KEY (servizio_annunci_id); END IF; END $$;