Skip to content

Instantly share code, notes, and snippets.

@mileszs
Created January 20, 2010 22:50
Show Gist options
  • Select an option

  • Save mileszs/282374 to your computer and use it in GitHub Desktop.

Select an option

Save mileszs/282374 to your computer and use it in GitHub Desktop.
## Drop this into a file in db/migrate ##
class AddMissingIndexes < ActiveRecord::Migration
def self.up
# These indexes were found by searching for AR::Base finds on your application
# It is strongly recommanded that you will consult a professional DBA about your infrastucture and implemntation before
# changing your database in that matter.
# There is a possibility that some of the indexes offered below is not required and can be removed and not added, if you require
# further assistance with your rails application, database infrastructure or any other problem, visit:
#
# http://www.railsmentors.org
# http://www.railstutor.org
# http://guides.rubyonrails.org
add_index :groups, :organization_id
add_index :groups, [:id, :type]
add_index :skus, :device_category_id
add_index :skus, :sku_category_id
add_index :skus, :wisdom_category_id
add_index :user_roles, :role_id
add_index :user_roles, :user_id
add_index :employments, :organization_id
add_index :employments, :person_id
add_index :devices, :parent_id
add_index :devices, :nvision_device_id
add_index :devices, :group_id
add_index :devices, :organization_id
add_index :devices, :device_type_id
add_index :actions, [:actionable_id, :actionable_type]
add_index :actions, :action_type_id
add_index :actions, :created_by
add_index :cabinet_assignments, :cabinet_status_code_id
add_index :cabinet_assignments, :organization_id
add_index :cabinet_assignments, :cabinet_id
add_index :cabinet_assignments, :cabinet_assignment_type_id
add_index :invoice_codings, :cbb_code_id
add_index :invoice_codings, :invoice_id
add_index :line_items, :parent_id
add_index :line_items, :quote_section_id
add_index :line_items, :sku_id
add_index :line_items, :created_by
add_index :software_installations, :device_id
add_index :software_installations, :installed_by
add_index :software_installations, :version_id
add_index :quotes, :bill_to_person_id
add_index :quotes, :signed_by
add_index :quotes, :address_id
add_index :quotes, :ship_to_person_id
add_index :quotes, :organization_id
add_index :quotes, :bill_to_address_id
add_index :quotes, :ship_to_address_id
add_index :quotes, :created_by
add_index :quotes, :sales_person_id
add_index :models, :organization_id
add_index :models, :device_category_id
add_index :assets_power_circuits, [:asset_id, :power_circuit_id]
add_index :assets_power_circuits, [:power_circuit_id, :asset_id]
add_index :components, :device_id
add_index :components, :sku_id
add_index :passphrases, :passphrase_type_id
add_index :subscriptions, :ticket_id
add_index :subscriptions, :project_id
add_index :subscriptions, :user_id
add_index :addresses, [:addressable_id, :addressable_type]
add_index :verifications, :verification_type_id
add_index :verifications, :ticket_id
add_index :verifications, :verifiable_id
add_index :verifications, :compliance_status_id
add_index :verifications, :created_by
add_index :verifications, [:verifiable_id, :verifiable_type]
add_index :old_attachments, [:attachable_id, :attachable_type]
add_index :org_aliases, :organization_id
add_index :project_actions, :project_id
add_index :project_actions, :action_type_id
add_index :project_actions, :created_by
add_index :assets, :device_id
add_index :assets, :nvision_asset_id
add_index :assets, :organization_id
add_index :assets, :deployment_status_id
add_index :assets, :cabinet_id
add_index :assets, :model_id
add_index :responsibilities, :user_id
add_index :responsibilities, :organization_id
add_index :responsibilities, :responsibility_type_id
add_index :responsibilities, :ticket_queue_id
add_index :cbb_codes, :invoice_id
add_index :bundles_skus, [:bundle_id, :sku_id]
add_index :bundles_skus, [:sku_id, :bundle_id]
add_index :power_circuits, :room_id
add_index :power_circuits, :panel_id
add_index :power_circuits, :cabinet_id
add_index :power_circuits, :power_circuit_status_id
add_index :passwords, :device_id
add_index :passwords, :organization_id
add_index :passwords, :password_type_id
add_index :telco_circuits, :medium_id
add_index :telco_circuits, :configuration_id
add_index :telco_circuits, :organization_id
add_index :telco_circuits, :encoding_type_id
add_index :telco_circuits, :carrier_id
add_index :telco_circuits, :ethernet_duplex_id
add_index :telco_circuits, :demarc_panel_id
add_index :telco_circuits, :destination_id
add_index :telco_circuits, :telco_circuit_type_id
add_index :telco_circuits, :central_office_id
add_index :telco_circuits, :downstream_organization_id
add_index :projects, :status_id
add_index :projects, :organization_id
add_index :projects, :owner_id
add_index :projects, :contact_id
add_index :projects, :created_by
add_index :rooms, :room_status_code_id
add_index :user_preferences, :preference_id
add_index :user_preferences, :user_id
add_index :panels, :panel_type_id
add_index :panels, :pdu_id
add_index :support_contracts, :support_contract_type_id
add_index :support_contracts, [:supportable_id, :supportable_type]
add_index :support_contracts, :vendor_id
add_index :amp_readings, :room_id
add_index :amp_readings, :amp_reading_set_id
add_index :amp_readings, :organization_id
add_index :amp_readings, :cabinet_id
add_index :amp_readings, :power_circuit_id
add_index :tickets, :ticket_category_id
add_index :tickets, :status_id
add_index :tickets, :recurring_ticket_id
add_index :tickets, :severity_id
add_index :tickets, :initial_owner_id
add_index :tickets, :parent_id
add_index :tickets, :project_id
add_index :tickets, :organization_id
add_index :tickets, :ticket_type_id
add_index :tickets, :timeframe_id
add_index :tickets, :resolution_category_id
add_index :tickets, :ticket_queue_id
add_index :tickets, :owner_id
add_index :tickets, :contact_id
add_index :tickets, :created_by
add_index :devices_tickets, [:device_id, :ticket_id]
add_index :devices_tickets, [:ticket_id, :device_id]
add_index :asset_components, [:id, :type]
add_index :asset_components, :asset_id
add_index :asset_components, :interface_type_id
add_index :demarc_racks, :room_id
add_index :cabinets, :room_id
add_index :timers, :timer_type_id
add_index :timers, :ticket_id
add_index :phones, [:phonable_id, :phonable_type]
add_index :versions, :software_product_id
add_index :emails, :person_id
add_index :recurring_tickets, :status_id
add_index :recurring_tickets, :organization_id
add_index :recurring_tickets, :timeframe_id
add_index :recurring_tickets, :contact_id
add_index :recurring_tickets, :owner_id
add_index :recurring_tickets, :ticket_queue_id
add_index :recurring_tickets, :created_by
add_index :device_types, :device_category_id
add_index :permissions, :role_id
add_index :people, [:id, :type]
add_index :software_products, :vendor_id
add_index :interface_addresses, :interface_address_type_id
add_index :interface_addresses, :telco_circuit_id
add_index :demarc_panels, :demarc_rack_id
add_index :backups, :device_id
add_index :group_memberships, :group_id
add_index :group_memberships, :person_id
add_index :backup_statuses, [:backupable_id, :backupable_type]
add_index :uploads, [:uploadable_id, :uploadable_type]
add_index :pdus, :room_id
add_index :configurations, :configuration_type_id
add_index :invoices, :department_id
add_index :invoices, :organization_id
add_index :invoices, :person_id
add_index :hops, :panel_id
add_index :hops, :room_id
add_index :hops, :telco_circuit_id
add_index :hops, :cabinet_id
add_index :hops, :hop_location_id
add_index :quote_sections, :quote_id
add_index :ip_addresses, [:ip_addressable_id, :ip_addressable_type]
add_index :ip_addresses, :ip_address_type_id
add_index :cbb_code_requirements, :cbb_code_id
end
def self.down
remove_index :groups, :organization_id
remove_index :groups, :column => [:id, :type]
remove_index :skus, :device_category_id
remove_index :skus, :sku_category_id
remove_index :skus, :wisdom_category_id
remove_index :user_roles, :role_id
remove_index :user_roles, :user_id
remove_index :employments, :organization_id
remove_index :employments, :person_id
remove_index :devices, :parent_id
remove_index :devices, :nvision_device_id
remove_index :devices, :group_id
remove_index :devices, :organization_id
remove_index :devices, :device_type_id
remove_index :actions, :column => [:actionable_id, :actionable_type]
remove_index :actions, :action_type_id
remove_index :actions, :created_by
remove_index :cabinet_assignments, :cabinet_status_code_id
remove_index :cabinet_assignments, :organization_id
remove_index :cabinet_assignments, :cabinet_id
remove_index :cabinet_assignments, :cabinet_assignment_type_id
remove_index :invoice_codings, :cbb_code_id
remove_index :invoice_codings, :invoice_id
remove_index :line_items, :parent_id
remove_index :line_items, :quote_section_id
remove_index :line_items, :sku_id
remove_index :line_items, :created_by
remove_index :software_installations, :device_id
remove_index :software_installations, :installed_by
remove_index :software_installations, :version_id
remove_index :quotes, :bill_to_person_id
remove_index :quotes, :signed_by
remove_index :quotes, :address_id
remove_index :quotes, :ship_to_person_id
remove_index :quotes, :organization_id
remove_index :quotes, :bill_to_address_id
remove_index :quotes, :ship_to_address_id
remove_index :quotes, :created_by
remove_index :quotes, :sales_person_id
remove_index :models, :organization_id
remove_index :models, :device_category_id
remove_index :assets_power_circuits, :column => [:asset_id, :power_circuit_id]
remove_index :assets_power_circuits, :column => [:power_circuit_id, :asset_id]
remove_index :components, :device_id
remove_index :components, :sku_id
remove_index :passphrases, :passphrase_type_id
remove_index :subscriptions, :ticket_id
remove_index :subscriptions, :project_id
remove_index :subscriptions, :user_id
remove_index :addresses, :column => [:addressable_id, :addressable_type]
remove_index :verifications, :verification_type_id
remove_index :verifications, :ticket_id
remove_index :verifications, :verifiable_id
remove_index :verifications, :compliance_status_id
remove_index :verifications, :created_by
remove_index :verifications, :column => [:verifiable_id, :verifiable_type]
remove_index :old_attachments, :column => [:attachable_id, :attachable_type]
remove_index :org_aliases, :organization_id
remove_index :project_actions, :project_id
remove_index :project_actions, :action_type_id
remove_index :project_actions, :created_by
remove_index :assets, :device_id
remove_index :assets, :nvision_asset_id
remove_index :assets, :organization_id
remove_index :assets, :deployment_status_id
remove_index :assets, :cabinet_id
remove_index :assets, :model_id
remove_index :responsibilities, :user_id
remove_index :responsibilities, :organization_id
remove_index :responsibilities, :responsibility_type_id
remove_index :responsibilities, :ticket_queue_id
remove_index :cbb_codes, :invoice_id
remove_index :bundles_skus, :column => [:bundle_id, :sku_id]
remove_index :bundles_skus, :column => [:sku_id, :bundle_id]
remove_index :power_circuits, :room_id
remove_index :power_circuits, :panel_id
remove_index :power_circuits, :cabinet_id
remove_index :power_circuits, :power_circuit_status_id
remove_index :passwords, :device_id
remove_index :passwords, :organization_id
remove_index :passwords, :password_type_id
remove_index :telco_circuits, :medium_id
remove_index :telco_circuits, :configuration_id
remove_index :telco_circuits, :organization_id
remove_index :telco_circuits, :encoding_type_id
remove_index :telco_circuits, :carrier_id
remove_index :telco_circuits, :ethernet_duplex_id
remove_index :telco_circuits, :demarc_panel_id
remove_index :telco_circuits, :destination_id
remove_index :telco_circuits, :telco_circuit_type_id
remove_index :telco_circuits, :central_office_id
remove_index :telco_circuits, :downstream_organization_id
remove_index :projects, :status_id
remove_index :projects, :organization_id
remove_index :projects, :owner_id
remove_index :projects, :contact_id
remove_index :projects, :created_by
remove_index :rooms, :room_status_code_id
remove_index :user_preferences, :preference_id
remove_index :user_preferences, :user_id
remove_index :panels, :panel_type_id
remove_index :panels, :pdu_id
remove_index :support_contracts, :support_contract_type_id
remove_index :support_contracts, :column => [:supportable_id, :supportable_type]
remove_index :support_contracts, :vendor_id
remove_index :amp_readings, :room_id
remove_index :amp_readings, :amp_reading_set_id
remove_index :amp_readings, :organization_id
remove_index :amp_readings, :cabinet_id
remove_index :amp_readings, :power_circuit_id
remove_index :tickets, :ticket_category_id
remove_index :tickets, :status_id
remove_index :tickets, :recurring_ticket_id
remove_index :tickets, :severity_id
remove_index :tickets, :initial_owner_id
remove_index :tickets, :parent_id
remove_index :tickets, :project_id
remove_index :tickets, :organization_id
remove_index :tickets, :ticket_type_id
remove_index :tickets, :timeframe_id
remove_index :tickets, :resolution_category_id
remove_index :tickets, :ticket_queue_id
remove_index :tickets, :owner_id
remove_index :tickets, :contact_id
remove_index :tickets, :created_by
remove_index :devices_tickets, :column => [:device_id, :ticket_id]
remove_index :devices_tickets, :column => [:ticket_id, :device_id]
remove_index :asset_components, :column => [:id, :type]
remove_index :asset_components, :asset_id
remove_index :asset_components, :interface_type_id
remove_index :demarc_racks, :room_id
remove_index :cabinets, :room_id
remove_index :timers, :timer_type_id
remove_index :timers, :ticket_id
remove_index :phones, :column => [:phonable_id, :phonable_type]
remove_index :versions, :software_product_id
remove_index :emails, :person_id
remove_index :recurring_tickets, :status_id
remove_index :recurring_tickets, :organization_id
remove_index :recurring_tickets, :timeframe_id
remove_index :recurring_tickets, :contact_id
remove_index :recurring_tickets, :owner_id
remove_index :recurring_tickets, :ticket_queue_id
remove_index :recurring_tickets, :created_by
remove_index :device_types, :device_category_id
remove_index :permissions, :role_id
remove_index :people, :column => [:id, :type]
remove_index :software_products, :vendor_id
remove_index :interface_addresses, :interface_address_type_id
remove_index :interface_addresses, :telco_circuit_id
remove_index :demarc_panels, :demarc_rack_id
remove_index :backups, :device_id
remove_index :group_memberships, :group_id
remove_index :group_memberships, :person_id
remove_index :backup_statuses, :column => [:backupable_id, :backupable_type]
remove_index :uploads, :column => [:uploadable_id, :uploadable_type]
remove_index :pdus, :room_id
remove_index :configurations, :configuration_type_id
remove_index :invoices, :department_id
remove_index :invoices, :organization_id
remove_index :invoices, :person_id
remove_index :hops, :panel_id
remove_index :hops, :room_id
remove_index :hops, :telco_circuit_id
remove_index :hops, :cabinet_id
remove_index :hops, :hop_location_id
remove_index :quote_sections, :quote_id
remove_index :ip_addresses, :column => [:ip_addressable_id, :ip_addressable_type]
remove_index :ip_addresses, :ip_address_type_id
remove_index :cbb_code_requirements, :cbb_code_id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment