Method: ActiveRecord::ConnectionAdapters::SchemaStatements#assume_migrated_upto_version

Defined in:
activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

#assume_migrated_upto_version(version, migrations_paths = nil) ⇒ Object



1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb', line 1084

def assume_migrated_upto_version(version, migrations_paths = nil)
  unless migrations_paths.nil?
    ActiveSupport::Deprecation.warn(<<~MSG.squish)
      Passing migrations_paths to #assume_migrated_upto_version is deprecated and will be removed in Rails 6.1.
    MSG
  end

  version = version.to_i
  sm_table = quote_table_name(schema_migration.table_name)

  migrated = migration_context.get_all_versions
  versions = migration_context.migrations.map(&:version)

  unless migrated.include?(version)
    execute "INSERT INTO #{sm_table} (version) VALUES (#{quote(version)})"
  end

  inserting = (versions - migrated).select { |v| v < version }
  if inserting.any?
    if (duplicate = inserting.detect { |v| inserting.count(v) > 1 })
      raise "Duplicate migration #{duplicate}. Please renumber your migrations to resolve the conflict."
    end
    execute insert_versions_sql(inserting)
  end
end