-- @author jennie@ybos.net
-- @author wirth@ybos.net

-- openacs port: Ola Hansson rockola@mail.com

-- dropping permissions
delete from acs_permissions
   where privilege in
      ('mp3_view_mp3','mp3_create_mp3','mp3_delete_mp3','mp3_modify_mp3',
       'mp3_view_playlist','mp3_create_playlist','mp3_delete_playlist',
       'mp3_modify_playlist','mp3_admin_mp3','mp3_admin_playlist',
       'mp3_admin');

delete from acs_privilege_hierarchy
    where privilege in
      ('mp3_view_mp3','mp3_create_mp3','mp3_delete_mp3','mp3_modify_mp3',
       'mp3_view_playlist','mp3_create_playlist','mp3_delete_playlist',
       'mp3_modify_playlist','mp3_admin_mp3','mp3_admin_playlist',
       'mp3_admin');

delete from acs_privilege_hierarchy
    where child_privilege in
      ('mp3_view_mp3','mp3_create_mp3','mp3_delete_mp3','mp3_modify_mp3',
       'mp3_view_playlist','mp3_create_playlist','mp3_delete_playlist',
       'mp3_modify_playlist','mp3_admin_mp3','mp3_admin_playlist',
       'mp3_admin');

delete from acs_privileges
    where privilege in
      ('mp3_view_mp3','mp3_create_mp3','mp3_delete_mp3','mp3_modify_mp3',
       'mp3_view_playlist','mp3_create_playlist','mp3_delete_playlist',
       'mp3_modify_playlist','mp3_admin_mp3','mp3_admin_playlist',
       'mp3_admin');


create function inline_0 ()
returns integer as '
declare
	v_play_rec		record;
	v_mp3_rec		record;
begin
   for v_play_rec in select playlist_id from mp3_playlists
   loop
     PERFORM mp3_playlist__delete (v_play_rec.playlist_id);
   end loop;
   for v_mp3_rec in select mp3_id from mp3_mp3s
   loop
     PERFORM mp3__delete (v_mp3_rec.mp3_id);
   end loop;

	return 0;
end;' language 'plpgsql';

select inline_0 ();
drop function inline_0 ();

-- drop package mp3_playlist;
-- drop package mp3;
drop function mp3_playlist__new (integer,varchar,boolean,integer,varchar,timestamptz,integer,varchar,integer);
drop function mp3_playlist__delete (integer);
drop function mp3_playlist__item_add (integer,integer,integer);
drop function mp3_playlist__item_remove (integer,integer);
drop function mp3_playlist__vote_cast (integer,integer,integer,integer,timestamptz);
drop function mp3_playlist__item_order_swap (integer,integer);
drop function mp3__new (integer,varchar,varchar);
drop function mp3__delete (integer);
drop function mp3__mark_as_deleted (integer);

drop view mp3_playlist_song_count;
drop view mp3_mp3s_not_deleted;
drop view mp3_mp3_playlist_map_view;
drop table mp3_mp3_playlist_map;
drop table mp3_mp3_stats;
drop table mp3_playlist_stats;
drop table mp3_votes;
drop table mp3_playlists;
drop table mp3_mp3s;

select acs_object_type__drop_type ('mp3_playlist','t');
select acs_object_type__drop_type ('mp3','t');
