Files
session_redis_public/attachment_s3/migrations/9.0.1.1.0/pre-migration.py
Guewen Baconnier 1d4f76de2b Migrate attachments s3 to new pattern
So remove the compatibility code altogether
2016-11-01 08:55:00 +01:00

21 lines
628 B
Python

# -*- coding: utf-8 -*-
# Copyright 2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
import os
def migrate(cr, version):
cr.execute("""
SELECT value FROM ir_config_parameter
WHERE key = 'ir_attachment.location'
""")
row = cr.fetchone()
bucket = os.environ.get('AWS_BUCKETNAME')
if row[0] == 's3' and bucket:
cr.execute("""
UPDATE ir_attachment
SET store_fname = 's3://' || %s || '/' || store_fname
WHERE store_fname IS NOT NULL AND store_fname NOT LIKE '%%/%%'
""", (os.environ['AWS_BUCKETNAME'],))