Forum OpenACS Development: jiml's file storage fixes thread

Collapse
Posted by Jim Lynch on
Hi. I've identified a couple of problems that I have solutions for in file storage; this thread will be a (short-lived) clearinghouse for that.

First, for your viewing pleasure, is the journal I kept while manually migrating the files in my file storage.

---

(in the description that follows, the table old_new_map is defined as

create table old_new_map
(
  object_id_old int;
  object_id_new int;
);
)

The first backup is after migrating users.

Next thing to do is add subsites which include a group of members; for each, add them to the mapping table.

Then add the additional groups (that have nothing to do with subsites) and add them to the mapping table.

also note that Steve Erquiagua tried once to register, got user 6677, he didn't get in, then he tried again, and got 6679; this is reflected in the perms of his file storage folder. (so: take 6677 out of old_new_map and out of where it exists somewhere in /home/nsadmin/filestorage-dump/(...)/perms)

There are two tables that need "on delete cascade" on their fk constraints. This is needed to be able to delete here are the alter-table sql statements to do that:

alter table 
    dav_site_node_folder_map 
drop constraint 
    dav_impls_folder_id_fk;

alter table 
    dav_site_node_folder_map 
add constraint 
    dav_impls_folder_id_fk 
        foreign key (folder_id) 
        references cr_folders 
            on delete cascade;

alter table 
    fs_root_folders 
drop constraint 
    fs_root_folder_folder_id_fk;

alter table 
    fs_root_folders 
add constraint 
    fs_root_folder_folder_id_fk 
        foreign key (folder_id) 
        references cr_folders 
            on delete cascade;
After this, delete the file-storage instance mounted on /files, create a new one, mount it on /files and set its parameters as follows:
  • AllowTextEdit 1
  • BehaveLikeFilesystemP 1
  • CategoriesP 1
  • ExposeRssP 1
  • GeneralCommentsP 1
  • StoreFilesInDatabaseP 1
  • UseWebDavP 1

Then save the params.

Also, had to fix the define_function_args call for plpgsql func content_type__is_content_type, which should receive one arg called object_type. Reason, this call kept returning false for every call, even when passing 'content_revision', the base case.

update 
    acs_function_args 
set 
    arg_name = 'OBJECT_TYPE' 
where function = 'CONTENT_TYPE__IS_CONTENT_TYPE';
Previously, folders were not created correctly, they were missing some type registrations. This was fixed by exporting the type registrations for each folder, then importing only those types that are content types; this was done in put-files/write-folders.tcl.

had to add (0,0) to old_new_map table; a permission referred to 0 (which is unregistered visitor)

This part starts to get weird... at this point I'm doing surgery on file-storage because it's lying about the table and id column to use for the content type file_storage_object, and saying fs_root_folders is that table, but that's wrong, and the consequence is you can't use content::* on them because they just don't work that way. I tried setting them blank but that didn't work (turns out later that it does work; I didn't call the refreshes), so I'm making a table with just an id column. Here's the sql to do that:

create table 
    file_storage_objects 
        (fs_object_id integer);

update acs_object_types set
    table_name = 'file_storage_objects',
    id_column = 'fs_object_id'
where
    object_type = 'file_storage_object';

select content_type__refresh_view('file_storage_object');

select content_type__refresh_trigger('file_storage_object');
Here's another version, to make the table blank. Note that this is a case where NULL and '' are -not- the same.
update acs_object_types set
    table_name = NULL,
    id_column = NULL
where
    object_type = 'file_storage_object';

select content_type__refresh_view('file_storage_object');

select content_type__refresh_trigger('file_storage_object');
You want to run this BEFORE putting anything other than folders into any file-storage instance.

This should be the second backup (but I think "Stuff" was done wrong).

Also, all the folders, items and revisions should have package_id set to the file-storage package.

Folders now import fine, and having imported them, did backup three.

there are 5 sets of item perms, which we will apply later; the privileges are always cm_perm and cm_write, which is not installed on the new openacs and I don't know what they are yet.

present status, folders work, items are finally importing, but there are two copies: one in the db, one in a file under /web/service... daveb says he thinks it's a bug in content::revision::update_content(), and the bug is that it calls cr_create_content_file in the place where it's trying to write a lob, which it succeeds at doing. (a little more detail, the call I refer to is in the top half of an if statement inside the "lob" case of the switch statement in content::revision::update_content() )

tried commenting that call out; it works. but an elusive permission problem is now preventing us from seeing the imported files; we can see folders and items, just not revisions.

Solved. The problem was in one of my import scripts; the revision id fed to the "set live revision" call was the id from the old openacs, and was not mapped to the new one. So I added a map() surrounding the old id.

Only thing left is a mime type issue where in at least one case the mime type "text/html; charset=iso-8859-1" is not present in the table "cr_mime_types".

try this:

insert into cr_mime_types 
    (mime_type, file_extension) 
values 
    ('text/html; charset=iso-8859-1', 'adp');
because this row was found in the old 4.6.3 openacs.
Collapse
Posted by Jim Lynch on
First, there are some missing on delete cascades. The following code should go in a postgres upgrade script; not sure it works in oracle.

Reason for this: attempting to delete a file storage instance results in the foreign key constraint violation named by the constraint below.

alter table 
    fs_root_folders 
drop constraint 
    fs_root_folder_folder_id_fk;

alter table 
    fs_root_folders 
add constraint 
    fs_root_folder_folder_id_fk 
        foreign key (folder_id) 
        references cr_folders 
            on delete cascade;

This diff alters the HEAD version of file storage as of the date of this message, so that new installs will add "on delete cascade" to the fk constraint.

Index: file-storage-create.sql
===================================================================
RCS file: /cvsroot/openacs-4/packages/file-storage/sql/postgresql/file-storage-create.sql,v
retrieving revision 1.22
diff -u -r1.22 file-storage-create.sql
--- file-storage-create.sql     26 May 2005 08:28:45 -0000      1.22
+++ file-storage-create.sql     9 Sep 2009 02:55:50 -0000
@@ -38,7 +38,7 @@
     -- JS: It is superfluous, and causes a lot of RI headaches
     folder_id   integer
                 constraint fs_root_folder_folder_id_fk
-                references cr_folders
+                references cr_folders on delete cascade
                 constraint fs_root_folder_folder_id_un
                 unique
 );
Collapse
Posted by Jim Lynch on
Next, file-storage is lying about which extension table to use for auxiliary storage for acs_object type file_storage_object, with the result being that the standard content::* api will not work, and therefore you have duplicate code, etc etc...

Let's just straighten out that lie here. We will set the aux table to NULL. The following code goes in an upgrade script for file-storage:

update acs_object_types set
    table_name = NULL,
    id_column = NULL
where
    object_type = 'file_storage_object';

select content_type__refresh_view('file_storage_object');

select content_type__refresh_trigger('file_storage_object');

and the following diff alters the data model create script accordingly:

Index: file-storage-create.sql
===================================================================
RCS file: /cvsroot/openacs-4/packages/file-storage/sql/postgresql/file-storage-create.sql,v
retrieving revision 1.22
diff -u -r1.22 file-storage-create.sql
--- file-storage-create.sql     26 May 2005 08:28:45 -0000      1.22
+++ file-storage-create.sql     9 Sep 2009 03:07:44 -0000
@@ -52,8 +52,8 @@
                                  -- first, before item metadata
        'File Storage Object',    -- pretty_name
        'File Storage Objects',   -- pretty_plural
-       'fs_root_folders',        -- table_name
-       'folder_id',             -- id_column
+       NULL,                     -- table_name
+       NULL,                    -- id_column
        'file_storage__get_title' -- name_method
 );

Collapse
Posted by Jim Lynch on
Next,

it turned out that adding on delete cascade to the fs_root_folders table wasn't enough and another table affected is in a completely different package, oacs-dav. Without both of them taken care of (and the lie mentioned above), you can't delete root folders.

Here is the upgrade script part:

alter table
    dav_site_node_folder_map
drop constraint
    dav_impls_folder_id_fk;

alter table dav_site_node_folder_map add constraint dav_impls_folder_id_fk foreign key (folder_id) references cr_folders on delete cascade;

And here is the diff for the create script:
Index: oacs-dav-create.sql
===================================================================
RCS file: /cvsroot/openacs-4/packages/oacs-dav/sql/postgresql/oacs-dav-create.sql,v
retrieving revision 1.2
diff -u -r1.2 oacs-dav-create.sql
--- oacs-dav-create.sql 12 Mar 2005 17:06:21 -0000      1.2
+++ oacs-dav-create.sql 9 Sep 2009 03:15:42 -0000
@@ -14,7 +14,7 @@
                         references site_nodes on delete cascade,
         folder_id       integer
                         constraint dav_impls_folder_id_fk
-                        references cr_folders,
+                        references cr_folders on delete cascade,
        enabled_p       boolean
 );

Collapse
Posted by Jim Lynch on
by the way... the page you're looking at right now or a prev incarnation of it does not validate... take a look at the validation results
Collapse
Posted by Emmanuelle Raffenne on
Hi Jim,

Newer version of forums fixes part of those errors. Others are due to the template used for this site (needs to be fixed), and maybe others to the content of your posts.

Collapse
Posted by Jim Lynch on
OK, I checked the cvs after dave committed the changes, and everything is done except for the upgrade script for oacs-dav, which replaces the dav_impls_folder_id_fk constraint, adding the "on delete cascade" to the folder_id fk.
Collapse
Posted by Dave Bauer on
Thanks jim! I missed those. They are there now.