aboutsummaryrefslogtreecommitdiffstats
path: root/db/migrate/030_add_some_indices.rb
blob: 6d9f365c09ddc6bbef6832744632e34e95d221ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class AddSomeIndices < ActiveRecord::Migration
    def self.up
        execute 'create index users_lower_email_index on users(lower(email))'

        add_index :info_requests, :created_at
        add_index :info_requests, :title # For checking duplicates at new request time

        execute "create index public_bodies_url_short_name_index on public_bodies(regexp_replace(replace(lower(short_name), ' ', '-'), '[^a-z0-9_-]', '', 'g'))"
        execute "create index public_body_versions_url_short_name_index on public_body_versions(regexp_replace(replace(lower(short_name), ' ', '-'), '[^a-z0-9_-]', '', 'g'))"
        execute "create index users_url_name_index on users (regexp_replace(replace(lower(name), ' ', '-'), '[^a-z0-9_-]', '', 'g'))"

        add_index :post_redirects, :email_token
        add_index :post_redirects, :token

    end

    def self.down
        execute 'drop index users_lower_email_index'

        remove_index :info_requests, :created_at
        remove_index :info_requests, :title 

        execute 'drop index users_url_name_index'
        execute 'drop index public_bodies_url_short_name_index'
        execute 'drop index public_body_versions_url_short_name_index'

        remove_index :post_redirects, :email_token
        remove_index :post_redirects, :token
    end
end