Sha256: c84c4c4f596b34ee9c5df17ca9f60596ca9106dbda99874a8001c520966e9c77

Contents?: true

Size: 1.36 KB

Versions: 37

Compression:

Stored size: 1.36 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 primary_key
        "version"
      end

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

      def create_table
        unless connection.table_exists?(table_name)
          connection.create_table(table_name, id: false) do |t|
            t.string :version, **connection.internal_string_options_for_primary_key
          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

      def table_exists?
        connection.data_source_exists?(table_name)
      end
    end

    def version
      super.to_i
    end
  end
end

Version data entries

37 entries across 35 versions & 5 rubygems

Version Path
activerecord-7.0.8.7 lib/active_record/schema_migration.rb
activerecord-7.0.8.6 lib/active_record/schema_migration.rb
activerecord-7.0.8.5 lib/active_record/schema_migration.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.8.4/lib/active_record/schema_migration.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/schema_migration.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/schema_migration.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/schema_migration.rb
activerecord-7.0.8.4 lib/active_record/schema_migration.rb
activerecord-7.0.8.1 lib/active_record/schema_migration.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-7.0.3.1/lib/active_record/schema_migration.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-7.0.2.3/lib/active_record/schema_migration.rb
activerecord-7.0.8 lib/active_record/schema_migration.rb
activerecord-7.0.7.2 lib/active_record/schema_migration.rb
activerecord-7.0.7.1 lib/active_record/schema_migration.rb
activerecord-7.0.7 lib/active_record/schema_migration.rb
activerecord-7.0.6 lib/active_record/schema_migration.rb
activerecord-7.0.5.1 lib/active_record/schema_migration.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activerecord-7.0.3.1/lib/active_record/schema_migration.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activerecord-7.0.2.3/lib/active_record/schema_migration.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/schema_migration.rb