Class: Rsodx::Cli::Commands::Generators::Migration

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/rsodx/cli/commands/generators/migration.rb

Instance Method Summary collapse

Instance Method Details

#call(name:) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rsodx/cli/commands/generators/migration.rb', line 13

def call(name:)
  timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
  file_name = File.join("db/migrations", "#{timestamp}_#{snake_case(name)}.rb")

  puts "📦 Creating migration: #{file_name}"
  FileUtils.mkdir_p("db/migrations")
  File.write(file_name, MIGRATION_TEMPLATE)

  puts "✅ Done"
rescue => e
  abort "❌ Failed to generate migration: #{e.message}"
end