Repository: klen/peewee_migrate

Issue:
Add support for multi-column index/unique 
I added a "multi-column index unique" definition according to the PeeWee documentation: http://docs.peewee-orm.com/en/latest/peewee/models.html#indexes-and-constraints but when I run **peewee_migrate** it doesn't generate the statements for the multi-column index. 

I was taking a look at your code (auto.py) and looks like you are not considering that case. It would be possible to add support for multicolumn index/unique ?

Adding manually the sentence using `migrator.add_index(model, *col_names, unique=False)` works but this means that I have to manually maintain autogenerated scripts and the other one for multi column indexes.

This is my model:

```
class Dog(BaseModel):
    id = PrimaryKeyField()
    user = ForeignKeyField(User, to_field='id', related_name='dogs', db_column='user_id')
    name = CharField(null=False)
    description = CharField(null=False)

    class Meta:
        indexes = (
            (('user', 'name'), True),  # This should generated a unique constraint of those two columns
        )
```

Comments:

Patch:
diff --git a/peewee_migrate/auto.py b/peewee_migrate/auto.py
index 1043072..38a5ea6 100644
--- a/peewee_migrate/auto.py
+++ b/peewee_migrate/auto.py
@@ -156,6 +156,22 @@ def diff_one(model1: pw.Model, model2: pw.Model, **kwargs) -> t.List[str]:
         else:
             changes.append(drop_index(model1, name))
 
+    # Check additional compound indexes
+    indexes1 = model1._meta.indexes
+    indexes2 = model2._meta.indexes
+
+    # Drop compound indexes
+    indexes_to_drop = set(indexes2) - set(indexes1)
+    for index in indexes_to_drop:
+        if isinstance(index[0], (list, tuple)) and len(index[0]) > 1:
+            changes.append(drop_index(model1, name=index[0]))
+
+    # Add compound indexes
+    indexes_to_add = set(indexes1) - set(indexes2)
+    for index in indexes_to_add:
+        if isinstance(index[0], (list, tuple)) and len(index[0]) > 1:
+            changes.append(add_index(model1, name=index[0], unique=index[1]))
+
     return changes
 
 


Test patch:
diff --git a/tests/test_auto.py b/tests/test_auto.py
index c770539..1be0853 100644
--- a/tests/test_auto.py
+++ b/tests/test_auto.py
@@ -95,6 +95,41 @@ def test_auto_multi_column_index():
     assert "indexes = [(('first_name', 'last_name'), True)]" in code
 
 
+def test_diff_multi_column_index():
+    from peewee_migrate.auto import diff_one
+
+    class Object(pw.Model):
+        first_name = pw.CharField()
+        last_name = pw.CharField()
+
+    class ObjectWithUniqueIndex(pw.Model):
+        first_name = pw.CharField()
+        last_name = pw.CharField()
+
+        class Meta:
+            indexes = ((("first_name", "last_name"), True),)
+
+    class ObjectWithNonUniqueIndex(pw.Model):
+        first_name = pw.CharField()
+        last_name = pw.CharField()
+
+        class Meta:
+            indexes = ((("first_name", "last_name"), False),)
+
+    changes = diff_one(ObjectWithUniqueIndex, Object)
+    assert len(changes) == 1
+    assert "('first_name', 'last_name'), unique=True)" in changes[0]
+
+    changes = diff_one(ObjectWithNonUniqueIndex, Object)
+    assert len(changes) == 1
+    assert "('first_name', 'last_name'), unique=False)" in changes[0]
+
+    changes = diff_one(ObjectWithNonUniqueIndex, ObjectWithUniqueIndex)
+    assert len(changes) == 2
+    assert "drop_index" in changes[0] and "('first_name', 'last_name')" in changes[0]
+    assert "('first_name', 'last_name'), unique=False)" in changes[1]
+
+
 def test_self_referencing_foreign_key_on_model_create():
     from peewee_migrate.auto import field_to_code