Module: DatabaseConsistency::Writers::Autofix::Helpers::Migration

Included in:
MigrationBase
Defined in:
lib/database_consistency/writers/autofix/helpers/migration.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#migration_configuration(name) ⇒ Object



19
20
21
22
23
24
# File 'lib/database_consistency/writers/autofix/helpers/migration.rb', line 19

def migration_configuration(name)
  {
    migration_name: name.camelcase,
    migration_version: ActiveRecord::Migration.current_version
  }
end

#migration_contextObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/database_consistency/writers/autofix/helpers/migration.rb', line 26

def migration_context
  if ActiveRecord::MigrationContext.instance_method(:initialize).arity == 1
    return ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths)
  end

  if ActiveRecord::Base.connection.respond_to?(:schema_migration)
    return ActiveRecord::MigrationContext.new(
      ActiveRecord::Migrator.migrations_paths,
      ActiveRecord::Base.connection.schema_migration
    )
  end

  ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths)
end

#migration_path(name) ⇒ Object



8
9
10
11
12
13
# File 'lib/database_consistency/writers/autofix/helpers/migration.rb', line 8

def migration_path(name)
  last = migration_context.migrations.last
  version = ActiveRecord::Migration.next_migration_number(last&.version.to_i + 1)

  "db/migrate/#{version}_#{name.underscore}.rb"
end

#migration_path_pattern(name) ⇒ Object



15
16
17
# File 'lib/database_consistency/writers/autofix/helpers/migration.rb', line 15

def migration_path_pattern(name)
  "db/migrate/*_#{name.underscore}.rb"
end