Forum OpenACS Development: Re: Relocating blob-stored data to files

Collapse
Posted by Rocael Hernández Rizzardini on
This worked for Galileo (PG):

db_foreach get_items {select item_id, revision_id from cr_revisions where item_id in (select item_id from cr_items where content_type = 'file_storage_object' and storage_type = 'lob')} {

    set file [ns_mktemp /tmp/fs-${revision_id}-XXXXXX]

    db_blob_get_file write_lob_content {
        select lob as content
        from cr_revisions
        where revision_id = :revision_id
    } -file $file


    db_transaction {
        set filename [cr_create_content_file $item_id $revision_id "$file"]
        db_dml set_file_content {
            update cr_revisions
            set content = :filename
            where revision_id = :revision_id
        }

        db_dml update_cr_item {
            update cr_items set storage_type = 'file' where item_id = :item_id
        }

        # now lets delete the lob file from the DB!
        db_dml update_cr_lob {
            update cr_revisions set lob = NULL where revision_id = :revision_id
        }
    }

ns_log notice "
--------------------------------------------------------------------------------
ROC debugging
file = $file
revision_id = '${revision_id}'
filename = '${filename}'
item_id = '${item_id}'
--------------------------------------------------------------------------------"

}