-- Create sequence if it doesn't exist
CREATE SEQUENCE IF NOT EXISTS hbcc_providers_id_seq;

-- Set the sequence to start from the maximum ID + 1
SELECT setval('hbcc_providers_id_seq', COALESCE((SELECT MAX(id) FROM hbcc_providers), 0) + 1, false);

-- Alter the id column to use the sequence
ALTER TABLE hbcc_providers ALTER COLUMN id SET DEFAULT nextval('hbcc_providers_id_seq');

-- Grant usage on the sequence
GRANT USAGE, SELECT ON SEQUENCE hbcc_providers_id_seq TO public;
