Sha256: c95383e21eaee7116e2a79ce2e85e91f8428245e7e8ad4dee3ca13839016fef2

Contents?: true

Size: 1.13 KB

Versions: 20

Compression:

Stored size: 1.13 KB

Contents

require "active_record/scoping/default"
require "active_record/scoping/named"

module ActiveRecord
  # This class is used to create a table that keeps track of values and keys such
  # as which environment migrations were run in.
  class InternalMetadata < ActiveRecord::Base # :nodoc:
    class << self
      def primary_key
        "key"
      end

      def table_name
        "#{table_name_prefix}#{ActiveRecord::Base.internal_metadata_table_name}#{table_name_suffix}"
      end

      def []=(key, value)
        find_or_initialize_by(key: key).update_attributes!(value: value)
      end

      def [](key)
        where(key: key).pluck(:value).first
      end

      def table_exists?
        connection.table_exists?(table_name)
      end

      # Creates an internal metadata table with columns +key+ and +value+
      def create_table
        unless table_exists?
          key_options = connection.internal_string_options_for_primary_key

          connection.create_table(table_name, id: false) do |t|
            t.string :key, key_options
            t.string :value
            t.timestamps
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
activerecord-5.1.7 lib/active_record/internal_metadata.rb
activerecord-5.1.7.rc1 lib/active_record/internal_metadata.rb
activerecord-5.1.6.2 lib/active_record/internal_metadata.rb
activerecord-5.1.6.1 lib/active_record/internal_metadata.rb
activerecord-5.1.6 lib/active_record/internal_metadata.rb
activerecord-5.1.5 lib/active_record/internal_metadata.rb
activerecord-5.1.5.rc1 lib/active_record/internal_metadata.rb
activerecord-5.1.4 lib/active_record/internal_metadata.rb
activerecord-5.1.4.rc1 lib/active_record/internal_metadata.rb
activerecord-5.1.3 lib/active_record/internal_metadata.rb
activerecord-5.1.3.rc3 lib/active_record/internal_metadata.rb
activerecord-5.1.3.rc2 lib/active_record/internal_metadata.rb
activerecord-5.1.3.rc1 lib/active_record/internal_metadata.rb
activerecord-5.1.2 lib/active_record/internal_metadata.rb
activerecord-5.1.2.rc1 lib/active_record/internal_metadata.rb
activerecord-5.1.1 lib/active_record/internal_metadata.rb
activerecord-5.1.0 lib/active_record/internal_metadata.rb
activerecord-5.1.0.rc2 lib/active_record/internal_metadata.rb
activerecord-5.1.0.rc1 lib/active_record/internal_metadata.rb
activerecord-5.1.0.beta1 lib/active_record/internal_metadata.rb