12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
61
|
# File 'lib/data_plan/generators/migration/migration_generator_core.rb', line 12
def calculate_migration(predefined_migration_name=nil)
require File.join( File.expand_path(File.dirname(__FILE__)),'lib','auto_migrations.rb')
require File.join( File.expand_path(File.dirname(__FILE__)),'lib','sexy_statements_hook.rb')
ActiveRecord::Migration.send :include, SexyStatementsHook
ActiveRecord::Migration.send :include, AutoMigrations
AutoMigrations.run
print "Migration generated. Self.up is:\n" + ActiveRecord::Migration.sexy_up
migration_name = predefined_migration_name
if migration_name.blank?
name = ActiveRecord::Migration.desired_migration_name
name = migration_default_name if name.blank?
migration_name = input("\nEnter filename [#{name}]:").strip.gsub(' ', '_')
migration_name = name if migration_name.blank?
end
up = ActiveRecord::Migration.sexy_up + " "
down = ActiveRecord::Migration.sexy_down
hints = <<HINT
# Hints on migrations syntax.
#
# add_column(table_name, column_name, type, options = {})
# Types are: :primary_key, :string, :text, :integer, :float, :datetime, :timestamp, :time, :date, :binary, :boolean.
#
# Other stuff:
# change_column(table_name, column_name, type, options = {}) - options as in add_column
# change_column_default(table_name, column_name, default)
# remove_column(table_name, column_name)
# rename_column(table_name, column_name, new_column_name)
#
# Sample: Don't add a primary key column
# create_table(:categories_suppliers, :id => false) do |t|
# t.column :category_id, :integer
# t.column :supplier_id, :integer
# end
#
# Sample: reload columns for a model from DB
# Person.reset_column_information
#
# More samples here: http://guides.rubyonrails.org/migrations.html
HINT
return up,down,hints,migration_name
end
|