4523: search index migration script
authorRadhika Chippada <radhika@curoverse.com>
Mon, 8 Dec 2014 20:22:11 +0000 (15:22 -0500)
committerRadhika Chippada <radhika@curoverse.com>
Mon, 8 Dec 2014 20:22:11 +0000 (15:22 -0500)
services/api/db/migrate/20141208185217_search_index.rb [new file with mode: 0644]
services/api/db/structure.sql
services/api/test/unit/arvados_model_test.rb

diff --git a/services/api/db/migrate/20141208185217_search_index.rb b/services/api/db/migrate/20141208185217_search_index.rb
new file mode 100644 (file)
index 0000000..79dea39
--- /dev/null
@@ -0,0 +1,29 @@
+class SearchIndex < ActiveRecord::Migration
+  def tables_with_searchable_columns
+    all_tables =  ActiveRecord::Base.connection.tables
+    all_tables.delete 'schema_migrations'
+
+    my_tables = []
+    all_tables.each do |table|
+      table_class = table.classify.constantize
+      if table_class.respond_to?('searchable_columns')
+        my_tables << table
+      end
+    end
+
+    my_tables
+  end
+
+  def up
+    tables_with_searchable_columns.each do |table|
+      indices = table.classify.constantize.searchable_columns('ilike')
+      add_index(table.to_sym, indices, name: "#{table}_search_index")
+    end
+  end
+
+  def down
+    tables_with_searchable_columns.each do |table, indices|
+      remove_index(table.to_sym, name: "#{table}_search_index")
+    end
+  end
+end
index 0da865d0a1d8fc0ada628a45640b6080c2adef12..059b43b2c964cb5ab68e5edde115989e6e1f91cf 100644 (file)
@@ -1376,13 +1376,6 @@ CREATE INDEX index_api_clients_on_created_at ON api_clients USING btree (created
 CREATE INDEX index_api_clients_on_modified_at ON api_clients USING btree (modified_at);
 
 
---
--- Name: index_api_clients_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
---
-
-CREATE INDEX index_api_clients_on_owner_uuid ON api_clients USING btree (owner_uuid);
-
-
 --
 -- Name: index_api_clients_on_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
@@ -1397,13 +1390,6 @@ CREATE UNIQUE INDEX index_api_clients_on_uuid ON api_clients USING btree (uuid);
 CREATE INDEX index_authkeys_on_user_and_expires_at ON authorized_keys USING btree (authorized_user_uuid, expires_at);
 
 
---
--- Name: index_authorized_keys_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
---
-
-CREATE INDEX index_authorized_keys_on_owner_uuid ON authorized_keys USING btree (owner_uuid);
-
-
 --
 -- Name: index_authorized_keys_on_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
@@ -1425,13 +1411,6 @@ CREATE INDEX index_collections_on_created_at ON collections USING btree (created
 CREATE INDEX index_collections_on_modified_at ON collections USING btree (modified_at);
 
 
---
--- Name: index_collections_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
---
-
-CREATE INDEX index_collections_on_owner_uuid ON collections USING btree (owner_uuid);
-
-
 --
 -- Name: index_collections_on_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
@@ -1474,13 +1453,6 @@ CREATE INDEX index_groups_on_group_class ON groups USING btree (group_class);
 CREATE INDEX index_groups_on_modified_at ON groups USING btree (modified_at);
 
 
---
--- Name: index_groups_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
---
-
-CREATE INDEX index_groups_on_owner_uuid ON groups USING btree (owner_uuid);
-
-
 --
 -- Name: index_groups_on_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
@@ -1488,13 +1460,6 @@ CREATE INDEX index_groups_on_owner_uuid ON groups USING btree (owner_uuid);
 CREATE UNIQUE INDEX index_groups_on_uuid ON groups USING btree (uuid);
 
 
---
--- Name: index_humans_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
---
-
-CREATE INDEX index_humans_on_owner_uuid ON humans USING btree (owner_uuid);
-
-
 --
 -- Name: index_humans_on_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
@@ -1523,13 +1488,6 @@ CREATE INDEX index_job_tasks_on_job_uuid ON job_tasks USING btree (job_uuid);
 CREATE INDEX index_job_tasks_on_modified_at ON job_tasks USING btree (modified_at);
 
 
---
--- Name: index_job_tasks_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
---
-
-CREATE INDEX index_job_tasks_on_owner_uuid ON job_tasks USING btree (owner_uuid);
-
-
 --
 -- Name: index_job_tasks_on_sequence; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
@@ -1579,13 +1537,6 @@ CREATE INDEX index_jobs_on_modified_at ON jobs USING btree (modified_at);
 CREATE INDEX index_jobs_on_output ON jobs USING btree (output);
 
 
---
--- Name: index_jobs_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
---
-
-CREATE INDEX index_jobs_on_owner_uuid ON jobs USING btree (owner_uuid);
-
-
 --
 -- Name: index_jobs_on_script; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
@@ -1635,13 +1586,6 @@ CREATE INDEX index_keep_disks_on_last_ping_at ON keep_disks USING btree (last_pi
 CREATE INDEX index_keep_disks_on_node_uuid ON keep_disks USING btree (node_uuid);
 
 
---
--- Name: index_keep_disks_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
---
-
-CREATE INDEX index_keep_disks_on_owner_uuid ON keep_disks USING btree (owner_uuid);
-
-
 --
 -- Name: index_keep_disks_on_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
@@ -1649,13 +1593,6 @@ CREATE INDEX index_keep_disks_on_owner_uuid ON keep_disks USING btree (owner_uui
 CREATE UNIQUE INDEX index_keep_disks_on_uuid ON keep_disks USING btree (uuid);
 
 
---
--- Name: index_keep_services_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
---
-
-CREATE INDEX index_keep_services_on_owner_uuid ON keep_services USING btree (owner_uuid);
-
-
 --
 -- Name: index_keep_services_on_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
@@ -1684,13 +1621,6 @@ CREATE INDEX index_links_on_head_uuid ON links USING btree (head_uuid);
 CREATE INDEX index_links_on_modified_at ON links USING btree (modified_at);
 
 
---
--- Name: index_links_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
---
-
-CREATE INDEX index_links_on_owner_uuid ON links USING btree (owner_uuid);
-
-
 --
 -- Name: index_links_on_tail_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
@@ -1740,13 +1670,6 @@ CREATE INDEX index_logs_on_modified_at ON logs USING btree (modified_at);
 CREATE INDEX index_logs_on_object_uuid ON logs USING btree (object_uuid);
 
 
---
--- Name: index_logs_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
---
-
-CREATE INDEX index_logs_on_owner_uuid ON logs USING btree (owner_uuid);
-
-
 --
 -- Name: index_logs_on_summary; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
@@ -1782,13 +1705,6 @@ CREATE INDEX index_nodes_on_hostname ON nodes USING btree (hostname);
 CREATE INDEX index_nodes_on_modified_at ON nodes USING btree (modified_at);
 
 
---
--- Name: index_nodes_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
---
-
-CREATE INDEX index_nodes_on_owner_uuid ON nodes USING btree (owner_uuid);
-
-
 --
 -- Name: index_nodes_on_slot_number; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
@@ -1817,13 +1733,6 @@ CREATE INDEX index_pipeline_instances_on_created_at ON pipeline_instances USING
 CREATE INDEX index_pipeline_instances_on_modified_at ON pipeline_instances USING btree (modified_at);
 
 
---
--- Name: index_pipeline_instances_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
---
-
-CREATE INDEX index_pipeline_instances_on_owner_uuid ON pipeline_instances USING btree (owner_uuid);
-
-
 --
 -- Name: index_pipeline_instances_on_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
@@ -1845,13 +1754,6 @@ CREATE INDEX index_pipeline_templates_on_created_at ON pipeline_templates USING
 CREATE INDEX index_pipeline_templates_on_modified_at ON pipeline_templates USING btree (modified_at);
 
 
---
--- Name: index_pipeline_templates_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
---
-
-CREATE INDEX index_pipeline_templates_on_owner_uuid ON pipeline_templates USING btree (owner_uuid);
-
-
 --
 -- Name: index_pipeline_templates_on_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
@@ -1866,13 +1768,6 @@ CREATE UNIQUE INDEX index_pipeline_templates_on_uuid ON pipeline_templates USING
 CREATE UNIQUE INDEX index_repositories_on_name ON repositories USING btree (name);
 
 
---
--- Name: index_repositories_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
---
-
-CREATE INDEX index_repositories_on_owner_uuid ON repositories USING btree (owner_uuid);
-
-
 --
 -- Name: index_repositories_on_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
@@ -1894,13 +1789,6 @@ CREATE INDEX index_specimens_on_created_at ON specimens USING btree (created_at)
 CREATE INDEX index_specimens_on_modified_at ON specimens USING btree (modified_at);
 
 
---
--- Name: index_specimens_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
---
-
-CREATE INDEX index_specimens_on_owner_uuid ON specimens USING btree (owner_uuid);
-
-
 --
 -- Name: index_specimens_on_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
@@ -1915,13 +1803,6 @@ CREATE UNIQUE INDEX index_specimens_on_uuid ON specimens USING btree (uuid);
 CREATE INDEX index_traits_on_name ON traits USING btree (name);
 
 
---
--- Name: index_traits_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
---
-
-CREATE INDEX index_traits_on_owner_uuid ON traits USING btree (owner_uuid);
-
-
 --
 -- Name: index_traits_on_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
@@ -1944,38 +1825,52 @@ CREATE INDEX index_users_on_modified_at ON users USING btree (modified_at);
 
 
 --
--- Name: index_users_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
+-- Name: index_users_on_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
+--
+
+CREATE UNIQUE INDEX index_users_on_uuid ON users USING btree (uuid);
+
+
+--
+-- Name: index_virtual_machines_on_hostname; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
 
-CREATE INDEX index_users_on_owner_uuid ON users USING btree (owner_uuid);
+CREATE INDEX index_virtual_machines_on_hostname ON virtual_machines USING btree (hostname);
 
 
 --
--- Name: index_users_on_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
+-- Name: index_virtual_machines_on_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
 
-CREATE UNIQUE INDEX index_users_on_uuid ON users USING btree (uuid);
+CREATE UNIQUE INDEX index_virtual_machines_on_uuid ON virtual_machines USING btree (uuid);
 
 
 --
--- Name: index_virtual_machines_on_hostname; Type: INDEX; Schema: public; Owner: -; Tablespace: 
+-- Name: job_tasks_search_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
 
-CREATE INDEX index_virtual_machines_on_hostname ON virtual_machines USING btree (hostname);
+CREATE INDEX job_tasks_search_index ON job_tasks USING btree (uuid, owner_uuid, modified_by_client_uuid, modified_by_user_uuid, job_uuid, parameters, output, created_by_job_task_uuid);
 
 
 --
--- Name: index_virtual_machines_on_owner_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
+-- Name: keep_disks_search_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
 
-CREATE INDEX index_virtual_machines_on_owner_uuid ON virtual_machines USING btree (owner_uuid);
+CREATE INDEX keep_disks_search_index ON keep_disks USING btree (uuid, owner_uuid, modified_by_client_uuid, modified_by_user_uuid, ping_secret, node_uuid, filesystem_uuid, keep_service_uuid);
 
 
 --
--- Name: index_virtual_machines_on_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace: 
+-- Name: keep_services_search_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
 
-CREATE UNIQUE INDEX index_virtual_machines_on_uuid ON virtual_machines USING btree (uuid);
+CREATE INDEX keep_services_search_index ON keep_services USING btree (uuid, owner_uuid, modified_by_client_uuid, modified_by_user_uuid, service_host, service_type);
+
+
+--
+-- Name: links_search_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
+--
+
+CREATE INDEX links_search_index ON links USING btree (uuid, owner_uuid, modified_by_client_uuid, modified_by_user_uuid, tail_uuid, link_class, name, head_uuid, properties);
 
 
 --
@@ -2299,5 +2194,3 @@ INSERT INTO schema_migrations (version) VALUES ('20140918153705');
 INSERT INTO schema_migrations (version) VALUES ('20140924091559');
 
 INSERT INTO schema_migrations (version) VALUES ('20141111133038');
-
-INSERT INTO schema_migrations (version) VALUES ('20141208164553');
\ No newline at end of file
index 7fab34c15fee6f5459eee5a5c23c4b931dcaf432..b9bd3308bcec39b1a05e14b0aa268eb7cbb44b61 100644 (file)
@@ -140,7 +140,7 @@ class ArvadosModelTest < ActiveSupport::TestCase
         search_index = indexes.select do |index|
           index.columns == search_index_columns
         end
-        assert !search_index.empty?, "#{table} does not have search index with all searchable columns"
+        assert !search_index.empty?, "#{table} does not have search index with all searchable columns #{search_index_columns}"
       end
     end
   end