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
  unless Motor::ApiConfig.table_exists?
    migration_template 'install_api_configs.rb', 'db/migrate/install_motor_api_configs.rb'
  end

  if with_api_actions?
    migration_template 'upgrade_motor_api_actions.rb', 'db/migrate/upgrade_motor_api_actions.rb'
  end

  migration_template 'install_notes.rb', 'db/migrate/install_motor_notes.rb' unless Motor::Note.table_exists?

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

#with_api_actions?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
# File 'lib/generators/motor/upgrade_generator.rb', line 35

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