instance method copy_table_indexes

Ruby on Rails 6.0.6

Since v5.2.8.1 Private

Available in: v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

copy_table_indexes(from, to, rename = {})

No documentation comment.

Parameters

from req
to req
rename opt = {}
Source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 430
        def copy_table_indexes(from, to, rename = {})
          indexes(from).each do |index|
            name = index.name
            if to == "a#{from}"
              name = "t#{name}"
            elsif from == "a#{to}"
              name = name[1..-1]
            end

            columns = index.columns
            if columns.is_a?(Array)
              to_column_names = columns(to).map(&:name)
              columns = columns.map { |c| rename[c] || c }.select do |column|
                to_column_names.include?(column)
              end
            end

            unless columns.empty?
              # index name can't be the same
              opts = { name: name.gsub(/(^|_)(#{from})_/, "\\1#{to}_"), internal: true }
              opts[:unique] = true if index.unique
              opts[:where] = index.where if index.where
              add_index(to, columns, opts)
            end
          end
        end

Defined in activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb line 430 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::ConnectionAdapters::SQLite3Adapter

Type at least 2 characters to search.

↑↓ navigate · open · esc close