START TRANSACTION;

ALTER TABLE quota_request
    ADD COLUMN additional_properties jsonb NOT NULL DEFAULT '{}';
ALTER TABLE quota_request
    ALTER COLUMN additional_properties DROP DEFAULT;

ALTER TABLE bot_service_configuration
    ALTER COLUMN location_segment_id DROP NOT NULL;

ALTER TABLE bot_service_configuration
    DROP CONSTRAINT bot_service_configuration_service_id_bot_configuration_id_l_key;

CREATE UNIQUE INDEX bot_service_configuration_key_location_null ON bot_service_configuration (service_id, bot_configuration_id) WHERE location_segment_id IS NULL;

CREATE UNIQUE INDEX bot_service_configuration_key_location_not_null ON bot_service_configuration (service_id, bot_configuration_id, location_segment_id) WHERE location_segment_id IS NOT NULL;


COMMIT;
