1
0
Fork 0

Adding indexes

This commit is contained in:
magnolia-fan 2011-09-26 04:48:31 +04:00
parent f328c319ed
commit 26808f9b66
2 changed files with 95 additions and 2 deletions

View File

@ -1,12 +1,10 @@
class Album < ActiveRecord::Base
belongs_to :artist
has_many :tracks, :order => 'bonus ASC, position ASC', :dependent => :destroy
has_many :local_brainz_cached_releases, :class_name => 'LocalBrainz::CachedRelease', :dependent => :destroy
has_many :album_formats
has_many :release_formats, :through => :album_formats
default_scope where(:master => true)
scope :with_non_masters, where(:master => [true, false])
def self.with_format f
joins(:release_formats).where(:release_formats => { :hash => f.to_s })

View File

@ -0,0 +1,95 @@
class AddIndexes < ActiveRecord::Migration
def up
# Artists
add_index :artists, :name
add_index :artists, :original_name
add_index :artists, :status
add_index :artists, :listeners
add_index :artist_aliases, :artist_id
add_index :artist_aliases, :name
add_index :artist_links, :artist_id
# Albums
add_index :albums, :name
add_index :albums, :artist_id
add_index :albums, :year
add_index :albums, :has_pic
add_index :albums, :master
add_index :release_formats, :hash
add_index :album_formats, :album_id
add_index :album_formats, :release_format_id
add_index :album_genres, :album_id
add_index :album_genres, :genre_id
add_index :album_styles, :album_id
add_index :album_styles, :style_id
# Tracks
add_index :tracks, :name
add_index :tracks, :album_id
add_index :tracks, :position
add_index :tracks, :bonus
add_index :track_artists, :track_id
add_index :track_artists, :artist_id
add_index :track_artists, :main
# Beathaven infrastructure
add_index :users, :name
add_index :users, :vkid
add_index :sessions, :user_id
add_index :sessions, :key
end
def down
# Artists
remove_index :artists, :column => :name
remove_index :artists, :column => :original_name
remove_index :artists, :column => :status
remove_index :artists, :column => :listeners
remove_index :artist_aliases, :column => :artist_id
remove_index :artist_aliases, :column => :name
remove_index :artist_links, :column => :artist_id
# Albums
remove_index :albums, :column => :name
remove_index :albums, :column => :artist_id
remove_index :albums, :column => :year
remove_index :albums, :column => :has_pic
remove_index :albums, :column => :master
remove_index :release_formats, :column => :hash
remove_index :album_formats, :column => :album_id
remove_index :album_formats, :column => :release_format_id
remove_index :album_genres, :column => :album_id
remove_index :album_genres, :column => :genre_id
remove_index :album_styles, :column => :album_id
remove_index :album_styles, :column => :style_id
# Tracks
remove_index :tracks, :column => :name
remove_index :tracks, :column => :album_id
remove_index :tracks, :column => :position
remove_index :tracks, :column => :bonus
remove_index :track_artists, :column => :track_id
remove_index :track_artists, :column => :artist_id
remove_index :track_artists, :column => :main
# Beathaven infrastructure
remove_index :users, :column => :name
remove_index :users, :column => :vkid
remove_index :sessions, :column => :user_id
remove_index :sessions, :column => :key
end
end