4523: update migration scripts to hard code tables and columns.
[arvados.git] / services / api / db / migrate / 20141208185217_search_index.rb
1 class SearchIndex < ActiveRecord::Migration
2   def tables_with_searchable_columns
3     {
4       "api_client_authorizations" => ["api_token", "created_by_ip_address", "last_used_by_ip_address", "default_owner_uuid", "scopes"],
5       "api_clients" => ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "name", "url_prefix"],
6       "authorized_keys" => ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "name", "key_type", "authorized_user_uuid", "public_key"],
7       "collections" => ["owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "portable_data_hash", "redundancy_confirmed_by_client_uuid", "uuid", "manifest_text", "name", "description", "properties"],
8       "groups" => ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "name", "description", "group_class"],
9       "humans" => ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "properties"],
10       "job_tasks" => ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "job_uuid", "parameters", "output", "created_by_job_task_uuid"],
11       "jobs" => ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "submit_id", "script", "script_version", "script_parameters", "cancelled_by_client_uuid", "cancelled_by_user_uuid", "output", "is_locked_by_uuid", "log", "tasks_summary", "runtime_constraints", "repository", "supplied_script_version", "docker_image_locator", "description", "state", "arvados_sdk_version"],
12       "keep_disks" => ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "ping_secret", "node_uuid", "filesystem_uuid", "keep_service_uuid"],
13       "keep_services" => ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "service_host", "service_type"],
14       "links" => ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "tail_uuid", "link_class", "name", "head_uuid", "properties"],
15       "logs" => ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "object_uuid", "event_type", "summary", "properties", "object_owner_uuid"],
16       "nodes" => ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "hostname", "domain", "ip_address", "info", "properties", "job_uuid"],
17       "pipeline_instances" => ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "pipeline_template_uuid", "name", "components", "properties", "state", "components_summary", "description"],
18       "pipeline_templates" => ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "name", "components", "description"],
19       "repositories" => ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "name", "fetch_url", "push_url"],
20       "specimens" => ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "material", "properties"],
21       "traits" => ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "name", "properties"],
22       "users" => ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "email", "first_name", "last_name", "identity_url", "prefs", "default_owner_uuid"],
23       "virtual_machines" => ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "hostname"],
24     }
25   end
26
27   def up
28     tables_with_searchable_columns.each do |table, columns|
29       add_index(table.to_sym, columns, name: "#{table}_search_index")
30     end
31   end
32
33   def down
34     tables_with_searchable_columns.each do |table, columns|
35       remove_index(table.to_sym, name: "#{table}_search_index")
36     end
37   end
38 end