Class: DynamicImage::Generators::UpgradeGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
ActiveRecord::Generators::Migration
Defined in:
lib/rails/generators/dynamic_image/upgrade/upgrade_generator.rb

Overview

Brings an existing table up to date with Schema.

bin/rails generate dynamic_image:upgrade Image

The migration is derived from the difference between the table and the schema, so running the generator again once the migration has been applied writes nothing. An application several releases behind gets a single migration with everything it's missing.

Only additive changes are generated. Columns are added nullable, and nullability differences are reported instead of altered: change_column_null fails on existing NULLs, and the generator can't know whether the data allows it.

Instance Method Summary collapse

Instance Method Details

#create_upgrade_migrationObject



27
28
29
30
31
32
33
34
35
# File 'lib/rails/generators/dynamic_image/upgrade/upgrade_generator.rb', line 27

def create_upgrade_migration
  if missing_columns.empty? && missing_indexes.empty?
    say_status(:identical, "#{table_name} is up to date", :blue)
    return
  end

  migration_template("upgrade_migration.rb",
                     File.join(db_migrate_path, "#{migration_name}.rb"))
end

#report_index_lockingObject



45
46
47
48
49
50
51
# File 'lib/rails/generators/dynamic_image/upgrade/upgrade_generator.rb', line 45

def report_index_locking
  return if missing_indexes.empty?

  say_status(:warn,
             "adding an index locks the table while it builds",
             :yellow)
end

#report_nullabilityObject



37
38
39
40
41
42
43
# File 'lib/rails/generators/dynamic_image/upgrade/upgrade_generator.rb', line 37

def report_nullability
  nullable_in_table.each do |name|
    say_status(:warn,
               "#{table_name}.#{name} should be NOT NULL",
               :yellow)
  end
end