mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-24 02:08:36 +00:00
Assume the following situation: * We have installed addons base, sale and attachment_s3 (hence base_attachment_object_storage as dependency) * All attachments are in S3 already * We run an upgrade of the 'base' addon, 'sale' is upgraded before attachment_s3 in the order of loading. * Sale updates the icon of the Sale menu * As attachment_s3 is not loaded yet, the attachment is created in the filestore Now if we don't persist the filestore or use different servers, we'll lose the images of the menus (or any attachment loaded by the install/upgrade of an addon). The implemented solution is to move the attachments from the filestore to the object storage at the loading of the module. However, this operation can take time and it shouldn't be run by 2 processes at the same time, so we want to detect if the module is loaded during a normal odoo startup or when some addons have been upgraded. There is nothing anymore at this point which allow us to know that modules just have been upgraded except... in the caller frame (load_modules). We have to rely on the inpect module and get the caller frame, which is not recommended, but seems the only way, besides, it's not called often and if _register_hook was called from another place, it would have no effect (unless the other place has a variable 'update_module' too).
Attachments on S3 storage ========================= This addon allows to store the attachments (documents and assets) on S3 or any other S3-compatible Object Storage. Configuration ------------- Activate S3 storage: * Create or set the system parameter with the key ``ir_attachment.location`` and the value in the form ``s3``. Configure accesses with environment variables: * ``AWS_HOST`` (not required if using AWS services) * ``AWS_ACCESS_KEY_ID`` * ``AWS_SECRET_ACCESS_KEY`` * ``AWS_BUCKETNAME`` Read-only mode: The bucket and the file key are stored in the attachment. So if you change the ``AWS_BUCKETNAME`` or the ``ir_attachment.location``, the existing attachments will still be read on their former bucket. But as soon as they are written over or new attachments are created, they will be created on the new bucket or on the other location (db or filesystem). This is a convenient way to be able to read the production attachments on a replication (since you have the credentials) without any risk to alter the production data. This addon must be added in the server wide addons with (``--load`` option): ``--load=web,web_kanban,attachment_s3`` Limitations ----------- * You need to call ``env['ir.attachment'].force_storage()`` after having changed the ``ir_attachment.location`` configuration in order to migrate the existing attachments to S3.