module ActiveRecord::ModelSpaces::DefaultTableSchemaCopier
Public Instance Methods
change_table_name(base_table_name, table_name, schema)
click to toggle source
change the table_name in a schema.rb fragment
# File lib/active_record/model_spaces/table_manager.rb, line 104 def change_table_name(base_table_name, table_name, schema) schema. gsub(/create_table \"#{base_table_name}\"/, "create_table \"#{table_name}\""). gsub(/add_index \"#{base_table_name}\"/, "add_index \"#{table_name}\"") end
copy_table_schema(connection, from_table_name, to_table_name)
click to toggle source
# File lib/active_record/model_spaces/table_manager.rb, line 92 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.instance_eval(to_table_schema) end
table_schema(connection, table_name)
click to toggle source
retrieve a schema.rb fragment pertaining to the table called table_name. uses a private Rails API
# File lib/active_record/model_spaces/table_manager.rb, line 99 def table_schema(connection, table_name) ActiveRecord::SchemaDumper.send(:new, connection).send(:table, table_name, StringIO.new).string end