Sha256: 9ec93373822735c10f4ff118af650656ebb5c07f29d507788780d62fec80de6e

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

# This will generate a migration for your application.
# 
# Example without columns:
#   rake generate:migration name=create_users
# 
# db/migrations/<number>_create_users.rb:
#   migration <number>, :create_users do
#     up do
#     end
#   
#     down do
#     end
#   end
# 
# Example with columns:
#   rake generate:migration name=create_users cols=username:string,email_address:string,created_at:date_time,updated_at:date_time
# 
# db/migrations/<number>_create_users.rb:
#   migration <number>, :create_users do
#     up do
#       create_table :users do
#         column :id, Integer, :serial => true
#         column :username, String, :size => 50
#         column :email, String, :size => 50
#         column :created_at, DateTime
#         column :updated_at, DateTime
#       end
#     end
#   
#     down do
#       drop_table :users
#     end
#   end
class MigrationGenerator < Genosaurus

  require_param :name
  
  def setup # :nodoc:
    @name_singular = param(:name).singular.underscore
    @name_plural = @name_singular.plural.underscore
    @name_singular_camel = @name_singular.camelcase
    @name_plural_camel = @name_plural.camelcase
    
    @table_name = param(:name).underscore.gsub("create_", "")
    @current_migration_number = next_migration_number
    @migration_name = "#{@current_migration_number}_#{param(:name).underscore}"
  end
  
  def migration_columns # :nodoc:
    [Mack::Genosaurus::Orm::ModelColumn.new(param(:name), "id:serial"), columns].flatten
  end
  
  def get_column_type(column) # :nodoc:
    column.column_type.camelcase
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mack-data_mapper-0.8.2 lib/mack-data_mapper/migration_generator/migration_generator.rb
mack-data_mapper-0.8.3 lib/mack-data_mapper/migration_generator/migration_generator.rb
mack-data_mapper-0.8.3.1 lib/mack-data_mapper/migration_generator/migration_generator.rb