Created
July 14, 2011 00:11
-
-
Save nesquena/1081618 to your computer and use it in GitHub Desktop.
Revisions
-
nesquena revised this gist
Aug 31, 2011 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ class IndexUsersEmails < ActiveRecord::Migration def self.up execute "END" add_pg_index :users, :email, :lock => false execute "BEGIN" end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ # This is here purely to allow me to use concurrent indexes module ActiveRecord::ConnectionAdapters::SchemaStatements # add_pg_index :users, :email, :lock => true def add_pg_index(table_name, column_name, options = {}) column_names = Array.wrap(column_name) index_name = index_name(table_name, :column => column_names) -
nesquena revised this gist
Aug 31, 2011 . 2 changed files with 30 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,7 @@ class IndexUsersEmails < ActiveRecord::Migration def self.up execute "END" execute "CREATE INDEX CONCURRENTLY index_users_on_email ON users(email)" execute "BEGIN" end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ # lib/extensions/migrations_ext.rb # This is here purely to allow me to use concurrent indexes module ActiveRecord::ConnectionAdapters::SchemaStatements # add_pg_index :feed_items, [:entity_id, :entity_type, :offset_seconds, :feedable_type, :id], :lock => true def add_pg_index(table_name, column_name, options = {}) column_names = Array.wrap(column_name) index_name = index_name(table_name, :column => column_names) if Hash === options # legacy support, since this param was a string index_type = options[:unique] ? "UNIQUE" : "" index_name = options[:name].to_s if options.key?(:name) index_lock = options[:lock] ? "" : "CONCURRENTLY" else index_type = options end if index_name.length > index_name_length raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' is too long; the limit is #{index_name_length} characters" end if index_name_exists?(table_name, index_name, false) raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' already exists" end quoted_column_names = quoted_columns_for_index(column_names, options).join(", ") execute "CREATE #{index_type} INDEX #{index_lock} #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} (#{quoted_column_names})" end end -
nesquena created this gist
Jul 14, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ class IndexUsersEmails < ActiveRecord::Migration def ddl_transaction(&block) block.call # do not start a transaction end def self.up execute "CREATE INDEX CONCURRENTLY index_users_on_email ON users(email)" end end