package com.raizlabs.android.dbflow.sql.migration;

import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;

import com.raizlabs.android.dbflow.sql.language.Index;
import com.raizlabs.android.dbflow.sql.language.property.IProperty;
import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper;

/**
 * Description: Defines and enables an Index structurally through a migration.
 */
public abstract class IndexMigration<TModel> extends BaseMigration {

    /**
     * The table to index on
     */
    private Class<TModel> onTable;

    /**
     * The name of this index
     */
    private String name;

    /**
     * The underlying index object.
     */
    private Index<TModel> index;

    public IndexMigration(@NonNull Class<TModel> onTable) {
        this.onTable = onTable;
    }

    @NonNull
    public abstract String getName();

    @CallSuper
    @Override
    public void onPreMigrate() {
        index = getIndex();
    }

    @Override
    public final void migrate(DatabaseWrapper database) {
        database.execSQL(getIndex().getQuery());
    }

    @CallSuper
    @Override
    public void onPostMigrate() {
        onTable = null;
        name = null;
        index = null;
    }

    /**
     * Adds a column to the underlying INDEX
     *
     * @param property The name of the column to add to the Index
     * @return This migration
     */
    public IndexMigration<TModel> addColumn(IProperty property) {
        getIndex().and(property);
        return this;
    }

    /**
     * Sets the INDEX to UNIQUE
     *
     * @return This migration.
     */
    public IndexMigration<TModel> unique() {
        getIndex().unique(true);
        return this;
    }

    /**
     * @return The index object based on the contents of this migration.
     */
    public Index<TModel> getIndex() {
        if (index == null) {
            index = new Index<TModel>(name).on(onTable);
        }
        return index;
    }

    /**
     * @return the query backing this migration.
     */
    public String getIndexQuery() {
        return getIndex().getQuery();
    }

}

@@ -571,80 +571,8 @@
 e;%0A%0A
-    /**%0A     * The name of this index%0A     */%0A    private String name;%0A%0A
     
@@ -611,16 +611,16 @@
 object.%0A
+
      */%0A
@@ -1120,29 +1120,8 @@
 ll;%0A
-        name = null;%0A
     
@@ -1823,20 +1823,25 @@
 TModel%3E(
-n
+getN
 ame
+()
 ).on(onT
@@ -2025,17 +2025,16 @@
 uery();%0A
+
     %7D%0A
-%0A
 %7D%0A

Fix broken IndexMigration