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
58 59 60 |
# File 'lib/bcms_tools/migration_helpers.rb', line 58 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
52 53 54 55 |
# File 'lib/bcms_tools/migration_helpers.rb', line 52 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
45 46 47 48 49 50 |
# File 'lib/bcms_tools/migration_helpers.rb', line 45 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 |