Class: BatchedBackgroundMigration::BatchedBackgroundMigrationGenerator

Inherits:
ActiveRecord::Generators::Base
  • Object
show all
Defined in:
lib/generators/batched_background_migration/batched_background_migration_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_batched_background_migration_class_and_specsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/generators/batched_background_migration/batched_background_migration_generator.rb', line 34

def create_batched_background_migration_class_and_specs
  if ee_only?
    template(
      "ee_batched_background_migration_job.template",
      File.join("ee/lib/ee/gitlab/background_migration/#{file_name}.rb")
    )

    template(
      "foss_batched_background_migration_job.template",
      File.join("lib/gitlab/background_migration/#{file_name}.rb")
    )

    template(
      "batched_background_migration_job_spec.template",
      File.join("ee/spec/lib/ee/gitlab/background_migration/#{file_name}_spec.rb")
    )
  else
    template(
      "batched_background_migration_job.template",
      File.join("lib/gitlab/background_migration/#{file_name}.rb")
    )

    template(
      "batched_background_migration_job_spec.template",
      File.join("spec/lib/gitlab/background_migration/#{file_name}_spec.rb")
    )
  end
end

#create_dictionary_fileObject



63
64
65
66
67
68
# File 'lib/generators/batched_background_migration/batched_background_migration_generator.rb', line 63

def create_dictionary_file
  template(
    "batched_background_migration_dictionary.template",
    File.join("db/docs/batched_background_migrations/#{file_name}.yml")
  )
end

#create_post_migration_and_specsObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/generators/batched_background_migration/batched_background_migration_generator.rb', line 22

def create_post_migration_and_specs
  migration_template(
    "queue_batched_background_migration.template",
    File.join(db_migrate_path, "queue_#{file_name}.rb")
  )

  template(
    "queue_batched_background_migration_spec.template",
    File.join("spec/migrations/#{migration_number}_queue_#{file_name}_spec.rb")
  )
end

#db_migrate_pathObject



70
71
72
# File 'lib/generators/batched_background_migration/batched_background_migration_generator.rb', line 70

def db_migrate_path
  super.sub("migrate", "post_migrate")
end

#validate!Object

Raises:

  • (ArgumentError)


16
17
18
19
20
# File 'lib/generators/batched_background_migration/batched_background_migration_generator.rb', line 16

def validate!
  raise ArgumentError, "table_name is required" unless table_name.present?
  raise ArgumentError, "column_name is required" unless column_name.present?
  raise ArgumentError, "feature_category is required" unless feature_category.present?
end