Repository: saleor/saleor

Issue:
Migration 0040_auto_20171205_0428 (Gin index) not working with long descriptions
I tried to update to the last release (11/2017) and got this error while applying migrations:

`psycopg2.OperationalError: index row size 2736 exceeds maximum 2712 for index "product_pro_name_5bb6fa_gin"`

TextField and Index are not really compatible.


Discussion:
@mperesson in the latest release we introduced a PostgreSQL full text search functionality for both storefront and dashboard. For faster searching we use a Gin index on a product name and description. It uses Btree, which is limited in size.

Depending on your project goals, there are a few things you might do to fix the problem. If you're not using search, or search is already provided by elasticsearch, you might want to remove the index from a product model entirely. Same solution might apply if your product count is in under few hundred.

In case you want to make use of the PostgreSQL search, you might want to add a [SearchVectorField](https://docs.djangoproject.com/en/1.11/ref/contrib/postgres/search/#searchvectorfield) to your model and keep it up to date on your own. This might be the best solution for a larger applications.
@salwator Why does this affect some deployments and not others? That does not seem right.
Hey, thanks for the reply!

I already removed the index cause I use elasticsearch (the new implementation is way better btw).

But I think I will not be the only one with this problem, and editing saleor model/migration might not be the best way to do it.
@mperesson  thank you for positive feedback regarding ES changes! As of GIN index size problem, you are absolutely right and this issue must be addressed anyway in a solution that works everywhere.

Resolving patch:
diff --git a/saleor/product/migrations/0043_auto_20171207_0839.py b/saleor/product/migrations/0043_auto_20171207_0839.py
new file mode 100644
--- /dev/null
+++ b/saleor/product/migrations/0043_auto_20171207_0839.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.5 on 2017-12-07 14:39
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('product', '0042_auto_20171206_0501'),
+    ]
+
+    operations = [
+        migrations.RemoveIndex(
+            model_name='product',
+            name='product_pro_name_5bb6fa_gin',
+        ),
+    ]
diff --git a/saleor/product/models.py b/saleor/product/models.py
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -5,7 +5,6 @@
 
 from django.conf import settings
 from django.contrib.postgres.fields import HStoreField
-from django.contrib.postgres.indexes import GinIndex
 from django.core.validators import MinValueValidator, RegexValidator
 from django.db import models
 from django.db.models import F, Max, Q
@@ -141,7 +140,6 @@ class Product(models.Model, ItemRange):
 
     class Meta:
         app_label = 'product'
-        indexes = [GinIndex(fields=['name', 'description'])]
         permissions = (
             ('view_product',
              pgettext_lazy('Permission description', 'Can view products')),


Test patch: