Module: ActiveRecord::ConnectionAdapters::SchemaStatements
- Defined in:
- lib/bcms_tools/migration_helpers.rb
Instance Method Summary collapse
-
#convert_database_to_innodb(aDatabase = nil) ⇒ Object
aDatabase may be nil to use the current database.
- #convert_tables_to_innodb(aTables, aDatabase = nil) ⇒ Object
-
#get_isam_tables(aDatabase = nil) ⇒ Object
The following methods and migration will convert all MyISAM tables to InnoDB format.
Instance Method Details
#convert_database_to_innodb(aDatabase = nil) ⇒ Object
aDatabase may be nil to use the current database
55 56 57 |
# File 'lib/bcms_tools/migration_helpers.rb', line 55 def convert_database_to_innodb(aDatabase=nil) convert_tables_to_innodb(get_isam_tables(aDatabase),aDatabase) end |
#convert_tables_to_innodb(aTables, aDatabase = nil) ⇒ Object
49 50 51 52 |
# File 'lib/bcms_tools/migration_helpers.rb', line 49 def convert_tables_to_innodb(aTables,aDatabase=nil) aDatabase ||= ActiveRecord::Base.connection.current_database aTables.each {|t| ActiveRecord::Base.connection.execute("ALTER TABLE #{aDatabase}.#{t} engine=InnoDB;")} end |
#get_isam_tables(aDatabase = nil) ⇒ Object
The following methods and migration will convert all MyISAM tables to InnoDB format.
example migration : gem ‘bcms_tools’; require ‘bcms_tools’
class ConvertAllToInnodb < ActiveRecord::Migration
def self.up
convert_database_to_innodb()
end
def self.down
end
end
42 43 44 45 46 47 |
# File 'lib/bcms_tools/migration_helpers.rb', line 42 def get_isam_tables(aDatabase=nil) aDatabase ||= ActiveRecord::Base.connection.current_database isam_tables = [] ActiveRecord::Base.connection.execute("SELECT table_name FROM information_schema.tables WHERE engine = 'MyISAM' and table_schema = '#{aDatabase}';").each {|s| isam_tables << s} isam_tables end |