Class: SongkickOauth2SchemaAddUniqueIndexes

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/songkick/oauth2/schema/20121025180447_songkick_oauth2_schema_add_unique_indexes.rb

Constant Summary collapse

FIELDS =
[:code, :refresh_token_hash]

Class Method Summary collapse

Class Method Details

.downObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/songkick/oauth2/schema/20121025180447_songkick_oauth2_schema_add_unique_indexes.rb', line 18

def self.down
  FIELDS.each do |field|
    remove_index :oauth2_authorizations, [:client_id, field]
    add_index :oauth2_authorizations, [:client_id, field]
  end
  remove_index :oauth2_authorizations, [:access_token_hash]
  add_index :oauth2_authorizations, [:access_token_hash]

  remove_index :oauth2_clients, [:client_id]
  add_index :oauth2_clients, [:client_id]

  remove_index :oauth2_clients, [:name]
end

.upObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/songkick/oauth2/schema/20121025180447_songkick_oauth2_schema_add_unique_indexes.rb', line 4

def self.up
  FIELDS.each do |field|
    remove_index :oauth2_authorizations, [:client_id, field]
    add_index :oauth2_authorizations, [:client_id, field], :unique => true
  end
  remove_index :oauth2_authorizations, [:access_token_hash]
  add_index :oauth2_authorizations, [:access_token_hash], :unique => true

  remove_index :oauth2_clients, [:client_id]
  add_index :oauth2_clients, [:client_id], :unique => true

  add_index :oauth2_clients, [:name], :unique => true
end