Module: ActiveRecord::ModelSpaces::MySQLTableSchemaCopier

Defined in:
lib/active_record/model_spaces/table_manager.rb

Class Method Summary collapse

Class Method Details

.change_table_name(from_table_name, to_table_name, schema) ⇒ Object



84
85
86
# File 'lib/active_record/model_spaces/table_manager.rb', line 84

def change_table_name(from_table_name, to_table_name, schema)
  schema.gsub(/CREATE TABLE `#{from_table_name}`/, "CREATE TABLE `#{to_table_name}`")
end

.copy_table_schema(connection, from_table_name, to_table_name) ⇒ Object



74
75
76
77
78
# File 'lib/active_record/model_spaces/table_manager.rb', line 74

def copy_table_schema(connection, from_table_name, to_table_name)
  from_table_schema = table_schema(connection, from_table_name)
  to_table_schema = change_table_name(from_table_name, to_table_name, from_table_schema)
  connection.execute(to_table_schema)
end

.table_schema(connection, table_name) ⇒ Object



80
81
82
# File 'lib/active_record/model_spaces/table_manager.rb', line 80

def table_schema(connection, table_name)
  connection.select_rows("SHOW CREATE TABLE `#{table_name}`").last.last
end