-- Deploy camper:order_campsite_type_options to pg
-- requires: schema_camper
-- requires: roles
-- requires: campsite_type_option

begin;

set search_path to camper, public;

create or replace function order_campsite_type_options(positions integer[]) returns void as
$$
	update campsite_type_option
	set position = cast(temp.position as integer)
	from unnest(positions) with ordinality as temp(option_id, position)
	where campsite_type_option_id = temp.option_id
	;
$$
	language sql
;

revoke execute on function order_campsite_type_options(integer[]) from public;
grant execute on function order_campsite_type_options(integer[]) to admin;

commit;
