method
copy_table
Ruby on Rails latest stable (v7.1.3.2)
-
0 notes -
Class: ActiveRecord::ConnectionAdapters::SQLiteAdapter
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0 (0)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (0)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
copy_table(from, to, options = {})
protected
Hide source
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 492 def copy_table(from, to, options = {}) #:nodoc: from_primary_key = primary_key(from) options[:primary_key] = from_primary_key if from_primary_key != 'id' unless options[:primary_key] options[:id] = !columns(from).detect{|c| c.name == 'id'}.nil? && 'id' == from_primary_key end create_table(to, options) do |definition| @definition = definition columns(from).each do |column| column_name = options[:rename] ? (options[:rename][column.name] || options[:rename][column.name.to_sym] || column.name) : column.name @definition.column(column_name, column.type, :limit => column.limit, :default => column.default, :precision => column.precision, :scale => column.scale, :null => column.null) end @definition.primary_key(from_primary_key) if from_primary_key yield @definition if block_given? end copy_table_indexes(from, to, options[:rename] || {}) copy_table_contents(from, to, @definition.columns.map {|column| column.name}, options[:rename] || {}) end