-- Help the object system construct pretty names
update acs_object_types
set name_method = 'pl_photo.name'
where object_type = 'pl_photo';

update acs_object_types
set name_method = 'pl_folder.name'
where object_type = 'pl_folder';

-- Grant 'admin' privilege to the creater of each
-- pl_photo and pl_folder.
begin
 for folder in (select p.folder_id as id, 
                       o.creation_user 
                from pl_folders p,
                     acs_objects o
                where p.folder_id = o.object_id) loop
   acs_permission.grant_permission (
       object_id => folder.id,
       grantee_id => folder.creation_user,
       privilege => 'admin'
    );
 end loop;

 for photo in (select p.photo_id as id,
                      o.creation_user
               from pl_photos p,
                    acs_objects o
               where p.photo_id = o.object_id) loop
   acs_permission.grant_permission (
       object_id => photo.id,
       grantee_id => photo.creation_user,
       privilege => 'admin'
    );
 end loop;
end;
/
show errors

-- All photos in a folder
-- get this exposure date by default
alter table pl_folders add (default_exp_date date);

-- Helpful for over-writing computer-generated names.
alter table pl_folders add (default_prefix varchar(250));

-- Deprecated table.
drop table pl_deleted_photos;

-- we use this temp table to avoid the "table is mutating" problem
-- when re-calculating the sort_n's after a photo is deleted.
create table pl_reshuffle_queue (
   folder_id integer
);

-- We use this sequence to make sure we can give
-- photos a unique sort_n when we move them into
-- a new folder.  We assume no folder will have
-- more than a million photos
create sequence pl_moved_photo_sort_n_seq start with 1000000;

@@ photo-album-lite-plsql
@@ photo-album-lite-triggers
@@ photo-album-lite-views

-- Fix any sort bugs in previous installation
begin
  insert into pl_reshuffle_queue (folder_id)
   select folder_id from pl_v_folders;
  pl_reshuffle;
end;
/
show errors
