Sha256: b9074a4ecbde9cb7307aee2e015d57a08baedcd6786bea46983899b9b2ed6e46

Contents?: true

Size: 1.16 KB

Versions: 33

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

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

33 entries across 33 versions & 3 rubygems

Version Path
activerecord-5.2.8.1 lib/active_record/internal_metadata.rb
activerecord-5.2.8 lib/active_record/internal_metadata.rb
activerecord-5.2.7.1 lib/active_record/internal_metadata.rb
activerecord-5.2.7 lib/active_record/internal_metadata.rb
activerecord-5.2.6.3 lib/active_record/internal_metadata.rb
activerecord-5.2.6.2 lib/active_record/internal_metadata.rb
activerecord-5.2.6.1 lib/active_record/internal_metadata.rb
activerecord-5.2.6 lib/active_record/internal_metadata.rb
activerecord-5.2.4.6 lib/active_record/internal_metadata.rb
activerecord-5.2.5 lib/active_record/internal_metadata.rb
activerecord-5.2.4.5 lib/active_record/internal_metadata.rb
activerecord-5.2.4.4 lib/active_record/internal_metadata.rb
activerecord-5.2.4.3 lib/active_record/internal_metadata.rb
activerecord-5.2.4.2 lib/active_record/internal_metadata.rb
activerecord-5.2.4.1 lib/active_record/internal_metadata.rb
activerecord-5.2.4 lib/active_record/internal_metadata.rb
activerecord-5.2.4.rc1 lib/active_record/internal_metadata.rb
spiral_form-0.1.1 vendor/bundle/gems/activerecord-5.2.3/lib/active_record/internal_metadata.rb
spiral_form-0.1.0 vendor/bundle/gems/activerecord-5.2.3/lib/active_record/internal_metadata.rb
activerecord-5.2.3 lib/active_record/internal_metadata.rb