Sha256: 9c4f376eb8251213d49af5cf7eb544f971f5efd2ad8d4a3d3fb06a1fd8bee3ad

Contents?: true

Size: 1.33 KB

Versions: 33

Compression:

Stored size: 1.33 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 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}#{ActiveRecord::Base.schema_migrations_table_name}#{table_name_suffix}"
      end

      def table_exists?
        ActiveSupport::Deprecation.silence { 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
        pluck(:version).map { |v| normalize_migration_number v }
      end
    end

    def version
      super.to_i
    end
  end
end

Version data entries

33 entries across 33 versions & 4 rubygems

Version Path
activerecord-5.0.7.2 lib/active_record/schema_migration.rb
activerecord-5.0.7.1 lib/active_record/schema_migration.rb
activerecord-5.0.7 lib/active_record/schema_migration.rb
activerecord-5.0.6 lib/active_record/schema_migration.rb
activerecord-5.0.6.rc1 lib/active_record/schema_migration.rb
activerecord-5.0.5 lib/active_record/schema_migration.rb
activerecord-5.0.5.rc2 lib/active_record/schema_migration.rb
activerecord-5.0.5.rc1 lib/active_record/schema_migration.rb
activerecord-5.0.4 lib/active_record/schema_migration.rb
activerecord-5.0.4.rc1 lib/active_record/schema_migration.rb
activerecord-5.0.3 lib/active_record/schema_migration.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activerecord-5.0.2/lib/active_record/schema_migration.rb
activerecord-5.0.2 lib/active_record/schema_migration.rb
activerecord-5.0.2.rc1 lib/active_record/schema_migration.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/schema_migration.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/schema_migration.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/schema_migration.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/schema_migration.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/schema_migration.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/schema_migration.rb