copy_table(from, to, options = {}) private

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 539
        def copy_table(from, to, options = {})
          from_primary_key = primary_key(from)
          options[:id] = false
          create_table(to, **options) do |definition|
            @definition = definition
            if from_primary_key.is_a?(Array)
              @definition.primary_keys from_primary_key
            end

            columns(from).each do |column|
              column_name = options[:rename] ?
                (options[:rename][column.name] ||
                 options[:rename][column.name.to_sym] ||
                 column.name) : column.name

              if column.has_default?
                type = lookup_cast_type_from_column(column)
                default = type.deserialize(column.default)
                default = -> { column.default_function } if default.nil?
              end

              column_options = {
                limit: column.limit,
                precision: column.precision,
                scale: column.scale,
                null: column.null,
                collation: column.collation,
                primary_key: column_name == from_primary_key
              }

              unless column.auto_increment?
                column_options[:default] = default
              end

              column_type = column.bigint? ? :bigint : column.type
              @definition.column(column_name, column_type, **column_options)
            end

            yield @definition if block_given?
          end
          copy_table_indexes(from, to, options[:rename] || {})
          copy_table_contents(from, to,
            @definition.columns.map(&:name),
            options[:rename] || {})
        end
Register or log in to add new notes.