Class: Motor::Generators::UpgradeGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Extended by:
Migration
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/motor/upgrade_generator.rb

Instance Method Summary collapse

Methods included from Migration

next_migration_number

Instance Method Details

#copy_migrationObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/generators/motor/upgrade_generator.rb', line 17

def copy_migration
  has_api_actions = Motor::Resource.all.any? do |resource|
    resource.preferences[:actions]&.any? { |action| action[:action_type] == 'api' }
  end

  unless Motor::ApiConfig.table_exists?
    migration_template 'install_api_configs.rb', 'db/migrate/install_motor_api_configs.rb'
  end

  migration_template 'upgrade_motor_api_actions.rb', 'db/migrate/upgrade_motor_api_actions.rb' if has_api_actions

  if Motor::ApiConfig.table_exists? && !has_api_actions
    puts 'The latest Motor Admin features are already configured'
  else
    puts 'Run `rake db:migrate` to update DB schema'
  end
end