create table us_selections (
        selection_id    integer 
			constraint us_selections_pk
			primary key
			constraint us_selections_id_fk
                        references acs_objects(object_id),
        package_id      integer
			constraint us_selections_pck_id_fk
                        references apm_packages(package_id),
        title           varchar(255),
        description     text,
        full_sql        text,
        bind_vars       text
);

create table us_bind_vars (
        selection_id    integer
			constraint us_bind_vars_sel_id_fk
			references us_selections on delete cascade,
        name            varchar(30),
        description     text,
        default_value   text,
	constraint us_bind_vars_pk
        primary key (selection_id, name)
);

-- Create the us_selection object type

select acs_object_type__create_type (
	'us_selection',
	'Selection',
	'Selections',
	'acs_object',
	'us_selections',
	'selection_id',
	null,
	'f',
	null,
	'us_selection__name'
);

\i users-selection-package-create.sql