Class: DataMigrate::RailsHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/data_migrate/rails_helper.rb

Class Method Summary collapse

Class Method Details

.data_migrator(direction, migrations, schema_migration = DataMigrate::RailsHelper.schema_migration, internal_metadata = DataMigrate::RailsHelper.internal_metadata, target_version = nil) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/data_migrate/rails_helper.rb', line 75

def data_migrator(
  direction,
  migrations,
  schema_migration = DataMigrate::RailsHelper.schema_migration,
   = DataMigrate::RailsHelper.,
  target_version = nil
)
  if rails_version_equal_to_or_higher_than_7_1
    DataMigrate::DataMigrator.new(direction, migrations, schema_migration, , target_version)
  else
    DataMigrate::DataMigrator.new(direction, migrations, schema_migration, target_version)
  end
end

.data_schema_delete_version(version) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/data_migrate/rails_helper.rb', line 57

def data_schema_delete_version(version)
  if rails_version_equal_to_or_higher_than_7_1
    data_schema_migration.delete_version(version)
  else
    data_schema_migration.where(version: version.to_s).delete_all
  end
end

.data_schema_migrationObject



65
66
67
68
69
70
71
72
73
# File 'lib/data_migrate/rails_helper.rb', line 65

def data_schema_migration
  if rails_version_equal_to_or_higher_than_7_2
    DataMigrate::DataSchemaMigration.new(ActiveRecord::Tasks::DatabaseTasks.migration_connection_pool)
  elsif rails_version_equal_to_or_higher_than_7_1
    DataMigrate::DataSchemaMigration.new(ActiveRecord::Tasks::DatabaseTasks.migration_connection)
  else
    DataMigrate::DataSchemaMigration
  end
end

.internal_metadataObject



21
22
23
24
25
26
27
28
29
# File 'lib/data_migrate/rails_helper.rb', line 21

def 
  if rails_version_equal_to_or_higher_than_7_2
    ActiveRecord::Base.connection_pool.
  elsif rails_version_equal_to_or_higher_than_7_1
    ActiveRecord::Base.connection.
  else
    ActiveRecord::InternalMetadata
  end
end

.rails_version_equal_to_or_higher_than_7_0Object



15
16
17
18
19
# File 'lib/data_migrate/rails_helper.rb', line 15

def rails_version_equal_to_or_higher_than_7_0
  return @rails_version_equal_to_or_higher_than_7_0 if defined?(@rails_version_equal_to_or_higher_than_7_0)

  @rails_version_equal_to_or_higher_than_7_0 = Gem::Dependency.new("railties", ">= 7.0").match?("railties", Gem.loaded_specs["railties"].version, true)
end

.rails_version_equal_to_or_higher_than_7_1Object



9
10
11
12
13
# File 'lib/data_migrate/rails_helper.rb', line 9

def rails_version_equal_to_or_higher_than_7_1
  return @equal_to_or_higher_than_7_1 if defined?(@equal_to_or_higher_than_7_1)

  @equal_to_or_higher_than_7_1 = Gem::Dependency.new("railties", ">= 7.1.0.alpha").match?("railties", Gem.loaded_specs["railties"].version, true)
end

.rails_version_equal_to_or_higher_than_7_2Object



4
5
6
7
8
# File 'lib/data_migrate/rails_helper.rb', line 4

def rails_version_equal_to_or_higher_than_7_2
  return @equal_to_or_higher_than_7_2 if defined?(@equal_to_or_higher_than_7_2)

  @equal_to_or_higher_than_7_2 = Gem::Dependency.new("railties", ">= 7.2.0.alpha").match?("railties", Gem.loaded_specs["railties"].version, true)
end

.schema_create_version(version) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/data_migrate/rails_helper.rb', line 49

def schema_create_version(version)
  if rails_version_equal_to_or_higher_than_7_1
    schema_migration.create_version(version)
  else
    schema_migration.create(version: version)
  end
end

.schema_migrationObject



31
32
33
34
35
36
37
38
39
# File 'lib/data_migrate/rails_helper.rb', line 31

def schema_migration
  if rails_version_equal_to_or_higher_than_7_2
    ActiveRecord::Base.connection_pool.schema_migration
  elsif rails_version_equal_to_or_higher_than_7_1
    ActiveRecord::Base.connection.schema_migration
  else
    ActiveRecord::SchemaMigration
  end
end

.schema_migration_versionsObject



41
42
43
44
45
46
47
# File 'lib/data_migrate/rails_helper.rb', line 41

def schema_migration_versions
  if rails_version_equal_to_or_higher_than_7_1
    schema_migration.versions
  else
    schema_migration.all.pluck(:version)
  end
end