alter table public.users add column if not exists username text null, add column if not exists password_hash text null; do $$ begin if not exists ( select 1 from pg_indexes where schemaname = 'public' and indexname = 'users_username_unique' ) then create unique index users_username_unique on public.users (username) where username is not null; end if; end $$;