mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-24 02:08:36 +00:00
Merge pull request #256 from dannyadair/dannyadair/swift-per-db
[13.0] attachment_swift: multi-tenancy use db name in container
This commit is contained in:
@@ -18,7 +18,7 @@ Configure accesses with environment variables:
|
|||||||
* ``SWIFT_ACCOUNT``
|
* ``SWIFT_ACCOUNT``
|
||||||
* ``SWIFT_PASSWORD``
|
* ``SWIFT_PASSWORD``
|
||||||
* ``SWIFT_REGION_NAME`` : optional region
|
* ``SWIFT_REGION_NAME`` : optional region
|
||||||
* ``SWIFT_WRITE_CONTAINER`` : Name of the container to use in the store (created if not existing)
|
* ``SWIFT_WRITE_CONTAINER`` : Name of the container to use in the store (created if not existing, optional {db} placeholder)
|
||||||
|
|
||||||
Read-only mode:
|
Read-only mode:
|
||||||
|
|
||||||
@@ -38,6 +38,20 @@ The System Parameter ``ir_attachment.storage.force.database`` can be customized
|
|||||||
force storage of files in the database. See the documentation of the module
|
force storage of files in the database. See the documentation of the module
|
||||||
``base_attachment_object_storage``.
|
``base_attachment_object_storage``.
|
||||||
|
|
||||||
|
Multi-tenancy
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Use the `{db}` placeholder to handle multi-tenancy.
|
||||||
|
|
||||||
|
On instances that hold multiple databases, it's preferable to have one container per database.
|
||||||
|
|
||||||
|
To handle this, you can insert the `{db}` placeholder in your container name variable ``SWIFT_WRITE_CONTAINER``.
|
||||||
|
It will be replaced by the database name.
|
||||||
|
This will give you a unique container per database.
|
||||||
|
|
||||||
|
As every attachment is saved with its container name, this doesn't affect the above-mentioned "Read-only mode" feature.
|
||||||
|
You could have multiple replicas read from the same production storage, but each write to their own container.
|
||||||
|
|
||||||
Python Dependencies
|
Python Dependencies
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
|||||||
@@ -146,6 +146,8 @@ class IrAttachment(models.Model):
|
|||||||
def _store_file_write(self, key, bin_data):
|
def _store_file_write(self, key, bin_data):
|
||||||
if self._storage() == 'swift':
|
if self._storage() == 'swift':
|
||||||
container = os.environ.get('SWIFT_WRITE_CONTAINER')
|
container = os.environ.get('SWIFT_WRITE_CONTAINER')
|
||||||
|
# replace {db} with the database name to handle multi-tenancy
|
||||||
|
container = container.format(db=self.env.cr.dbname)
|
||||||
conn = self._get_swift_connection()
|
conn = self._get_swift_connection()
|
||||||
conn.put_container(container)
|
conn.put_container(container)
|
||||||
filename = 'swift://{}/{}'.format(container, key)
|
filename = 'swift://{}/{}'.format(container, key)
|
||||||
|
|||||||
Reference in New Issue
Block a user