示例#1
0
    def check_indexes(self, cr, model_names):
        """ Create or drop column indexes for the given models. """
        expected = [("%s_%s_index" % (Model._table, field.name), Model._table,
                     field.name, field.index) for model_name in model_names
                    for Model in [self.models[model_name]]
                    if Model._auto and not Model._abstract
                    for field in Model._fields.values()
                    if field.column_type and field.store]
        if not expected:
            return

        cr.execute("SELECT indexname FROM pg_indexes WHERE indexname IN %s",
                   [tuple(row[0] for row in expected)])
        existing = {row[0] for row in cr.fetchall()}

        for indexname, tablename, columnname, index in expected:
            if index and indexname not in existing:
                try:
                    with cr.savepoint(flush=False):
                        sql.create_index(cr, indexname, tablename,
                                         ['"%s"' % columnname])
                except psycopg2.OperationalError:
                    _schema.error("Unable to add index for %s", self)
            elif not index and indexname in existing:
                sql.drop_index(cr, indexname, tablename)
示例#2
0
def migrate(env, version):
    fill_product_variant_combination_table(env)
    openupgrade.load_data(env.cr, "product",
                          "migrations/13.0.1.2/noupdate_changes.xml")
    convert_image_attachments(env)
    empty_template_pricelist_company(env)
    sql.drop_index(env.cr, 'product_template_attribute_value_ou_migration_idx',
                   "product_template_attribute_value")