~akretion-team/openerp-product-attributes/70-update-and-fix-product-gtin

« back to all changes in this revision

Viewing changes to product_custom_attributes/migrations/7.0.0.2/post-migration.py

  • Committer: Guewen Baconnier
  • Author(s): Leonardo Pistone
  • Date: 2013-12-19 10:22:54 UTC
  • mfrom: (228.1.1 7.0-fix-1259975-migration-lep)
  • Revision ID: guewen.baconnier@camptocamp.com-20131219102254-db5tm7xud7wt3i3m
[fix] do not migrate on a fresh db

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
 
27
27
def migrate(cr, version):
28
 
    logger.info("Migrating product_custom_attributes from version %s", version)
29
 
    cr.execute("UPDATE product_template pt "
30
 
               "SET attribute_set_id = (SELECT pp.attribute_set_id "
31
 
               "                        FROM product_product pp WHERE "
32
 
               "                        pp.product_tmpl_id = pt.id "
33
 
               "                        LIMIT 1)"
34
 
               "WHERE pt.attribute_set_id IS NULL")
35
 
    cr.execute('ALTER TABLE product_product DROP COLUMN attribute_set_id')
 
28
    if version:  # do not run on a fresh DB, see lp:1259975
 
29
        logger.info("Migrating product_custom_attributes from version %s", version)
 
30
        cr.execute("UPDATE product_template pt "
 
31
                   "SET attribute_set_id = (SELECT pp.attribute_set_id "
 
32
                   "                        FROM product_product pp WHERE "
 
33
                   "                        pp.product_tmpl_id = pt.id "
 
34
                   "                        LIMIT 1)"
 
35
                   "WHERE pt.attribute_set_id IS NULL")
 
36
        cr.execute('ALTER TABLE product_product DROP COLUMN attribute_set_id')