Class: MigrationGenerator

Inherits:
Genosaurus
  • Object
show all
Defined in:
lib/mack-data_mapper/migration_generator/migration_generator.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#get_column_type(column) ⇒ Object

:nodoc:



53
54
55
# File 'lib/mack-data_mapper/migration_generator/migration_generator.rb', line 53

def get_column_type(column) # :nodoc:
  column.column_type.camelcase
end

#migration_columnsObject

:nodoc:



49
50
51
# File 'lib/mack-data_mapper/migration_generator/migration_generator.rb', line 49

def migration_columns # :nodoc:
  [Mack::Genosaurus::Orm::ModelColumn.new(param(:name), "id:serial"), columns].flatten
end

#setupObject

:nodoc:



38
39
40
41
42
43
44
45
46
47
# File 'lib/mack-data_mapper/migration_generator/migration_generator.rb', line 38

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