Sha256: ea34bce0f533f5a27bb0c6655365b2e64a493d86c3b5aa11e8e66fc59001f3f5

Contents?: true

Size: 1.42 KB

Versions: 22

Compression:

Stored size: 1.42 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 which migrations
  # have been applied to a given database. When a migration is run, its schema
  # number is inserted in to the `SchemaMigration.table_name` so it doesn't need
  # to be executed the next time.
  class SchemaMigration < ActiveRecord::Base # :nodoc:
    class << self
      def _internal?
        true
      end

      def primary_key
        "version"
      end

      def table_name
        "#{table_name_prefix}#{schema_migrations_table_name}#{table_name_suffix}"
      end

      def table_exists?
        connection.table_exists?(table_name)
      end

      def create_table
        unless table_exists?
          version_options = connection.internal_string_options_for_primary_key

          connection.create_table(table_name, id: false) do |t|
            t.string :version, **version_options
          end
        end
      end

      def drop_table
        connection.drop_table table_name, if_exists: true
      end

      def normalize_migration_number(number)
        "%.3d" % number.to_i
      end

      def normalized_versions
        all_versions.map { |v| normalize_migration_number v }
      end

      def all_versions
        order(:version).pluck(:version)
      end
    end

    def version
      super.to_i
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
activerecord-6.0.6.1 lib/active_record/schema_migration.rb
activerecord-6.0.6 lib/active_record/schema_migration.rb
activerecord-6.0.5.1 lib/active_record/schema_migration.rb
activerecord-6.0.5 lib/active_record/schema_migration.rb
activerecord-6.0.4.8 lib/active_record/schema_migration.rb
activerecord-6.0.4.7 lib/active_record/schema_migration.rb
activerecord-6.0.4.6 lib/active_record/schema_migration.rb
activerecord-6.0.4.5 lib/active_record/schema_migration.rb
activerecord-6.0.4.4 lib/active_record/schema_migration.rb
activerecord-6.0.4.3 lib/active_record/schema_migration.rb
activerecord-6.0.4.2 lib/active_record/schema_migration.rb
activerecord-6.0.4.1 lib/active_record/schema_migration.rb
activerecord-6.0.4 lib/active_record/schema_migration.rb
activerecord-6.0.3.7 lib/active_record/schema_migration.rb
activerecord-6.0.3.6 lib/active_record/schema_migration.rb
activerecord-6.0.3.5 lib/active_record/schema_migration.rb
activerecord-6.0.3.4 lib/active_record/schema_migration.rb
activerecord-6.0.3.3 lib/active_record/schema_migration.rb
activerecord-6.0.3.2 lib/active_record/schema_migration.rb
activerecord-6.0.3.1 lib/active_record/schema_migration.rb