class Effective::Generators::MigrationGenerator
Public Instance Methods
create_migration()
click to toggle source
rails generate effective:migration courses body:text –database example
# File lib/generators/effective/migration_generator.rb, line 30 def create_migration if invoked_attributes.present? args = ["create_#{plural_name}"] + (invokable(invoked_attributes) | timestamps) args += ["--database", options['database']] if options['database'] Rails::Generators.invoke('migration', args) return end return if with_resource_tenant do table_name = resource.klass.table_name if ActiveRecord::Base.connection.table_exists?(table_name) say_status(:error, "#{table_name} table already exist. We can't migrate (yet). Exiting.", :red) true end end if resource.model_attributes.blank? say_status(:error, "No model attributes present. Please add the effective_resource do ... end block and try again", :red) return end args = ["create_#{plural_name}"] + invokable(resource.model_attributes) - timestamps args += ["--database", options['database']] if options['database'] if options['database'].blank? && defined?(Tenant) args += ["--database", resource.klass.name.split('::').first.downcase] end Rails::Generators.invoke('migration', args) end
invoke_migration()
click to toggle source
# File lib/generators/effective/migration_generator.rb, line 25 def invoke_migration say_status :invoke, :migration, :white end
validate_resource()
click to toggle source
# File lib/generators/effective/migration_generator.rb, line 21 def validate_resource exit unless resource_valid? end
Protected Instance Methods
timestamps()
click to toggle source
# File lib/generators/effective/migration_generator.rb, line 64 def timestamps ['created_at:datetime', 'updated_at:datetime'] end