From e46874d04a4974ddb655962b6da8afb2928bc991 Mon Sep 17 00:00:00 2001
From: BoHong Li <a60814billy@gmail.com>
Date: Tue, 28 Mar 2017 15:25:36 +0800
Subject: [PATCH] fix: Other dialect duplicated add index problem

Detect is using SQLite to add index
---
 .../20150915153700-change-notes-title-to-text.js     | 12 +++++++++---
 lib/utils.js                                         |  5 +++++
 2 files changed, 14 insertions(+), 3 deletions(-)
 create mode 100644 lib/utils.js

diff --git a/lib/migrations/20150915153700-change-notes-title-to-text.js b/lib/migrations/20150915153700-change-notes-title-to-text.js
index 2b3a82b..9d00f15 100644
--- a/lib/migrations/20150915153700-change-notes-title-to-text.js
+++ b/lib/migrations/20150915153700-change-notes-title-to-text.js
@@ -1,11 +1,14 @@
 'use strict'
+const isSQLite = require('../utils').isSQLite
 module.exports = {
   up: function (queryInterface, Sequelize) {
     return queryInterface.changeColumn('Notes', 'title', {
       type: Sequelize.TEXT
     }).then(function () {
-      // manual added index will be removed in sqlite
-      return queryInterface.addIndex('Notes', ['shortid'])
+      if (isSQLite(queryInterface.sequelize)) {
+        // manual added index will be removed in sqlite
+        return queryInterface.addIndex('Notes', ['shortid'])
+      }
     })
   },
 
@@ -13,7 +16,10 @@ module.exports = {
     return queryInterface.changeColumn('Notes', 'title', {
       type: Sequelize.STRING
     }).then(function () {
-      return queryInterface.addIndex('Notes', ['shortid'])
+      if (isSQLite(queryInterface.sequelize)) {
+        // manual added index will be removed in sqlite
+        return queryInterface.addIndex('Notes', ['shortid'])
+      }
     })
   }
 }
diff --git a/lib/utils.js b/lib/utils.js
new file mode 100644
index 0000000..6c36549
--- /dev/null
+++ b/lib/utils.js
@@ -0,0 +1,5 @@
+'use strict'
+
+exports.isSQLite = function isSQLite (sequelize) {
+  return sequelize.options.dialect === 'sqlite'
+}