30
31
32
33
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
|
# 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
|