Class: HumanDomain::Generate::MigrationsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/human_domain/generate/migrations_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/generators/human_domain/generate/migrations_generator.rb', line 14

def next_migration_number(dirname)
  current_migration_timestamp = current_migration_number(dirname)

  if ActiveRecord::Base.timestamped_migrations
    timestamp_str = Time.new.utc.strftime("%Y%m%d%H%M%S")

    # Check if timestamp is the same with previous migration
    # due to fast generation in the same second
    if timestamp_str == current_migration_timestamp.to_s
      "%.3d" % (current_migration_timestamp + 1)
    else
      timestamp_str
    end
  else
    "%.3d" % (current_migration_timestamp + 1)
  end
end

Instance Method Details

#create_migration_filesObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/generators/human_domain/generate/migrations_generator.rb', line 33

def create_migration_files
  source_dir = 'db/migrate/human_domain'
  destination_dir = 'db/migrate'

  migration_template(
    "#{source_dir}/0001_create_blood_classification_systems.rb",
    "#{destination_dir}/create_blood_classification_systems.rb"
  )

  migration_template(
    "#{source_dir}/0002_create_blood_group_names.rb",
    "#{destination_dir}/create_blood_group_names.rb"
  )
end