11103: Omit mounts from container_requests and definition from workflows for full...
[arvados.git] / services / api / db / migrate / 20170216170823_no_cr_mounts_and_workflow_def_in_full_text_search_index.rb
diff --git a/services/api/db/migrate/20170216170823_no_cr_mounts_and_workflow_def_in_full_text_search_index.rb b/services/api/db/migrate/20170216170823_no_cr_mounts_and_workflow_def_in_full_text_search_index.rb
new file mode 100644 (file)
index 0000000..3d4a606
--- /dev/null
@@ -0,0 +1,28 @@
+class NoCrMountsAndWorkflowDefInFullTextSearchIndex < ActiveRecord::Migration
+  def fts_indexes
+    {
+      "container_requests" => "container_requests_full_text_search_idx",
+      "workflows" => "workflows_full_text_search_idx",
+    }
+  end
+
+  def up
+    # remove existing fts index and recreate for container_requests and workflows
+    fts_indexes.each do |t, i|
+      t.classify.constantize.reset_column_information
+      ActiveRecord::Base.connection.indexes(t).each do |idx|
+        if idx.name == i
+          remove_index t.to_sym, :name => i
+          break
+        end
+      end
+      execute "CREATE INDEX #{i} ON #{t} USING gin(#{t.classify.constantize.full_text_tsvector});"
+    end
+  end
+
+  def down
+    fts_indexes.each do |t, i|
+      remove_index t.to_sym, :name => i
+    end
+  end
+end