Class: Strata::CLI::Generators::Migration

Inherits:
Group
  • Object
show all
Defined in:
lib/strata/cli/generators/migration.rb

Overview

Generates migration YAML files from templates.

Instance Method Summary collapse

Methods inherited from Group

exit_on_failure?, source_root

Instance Method Details

#create_migration_fileObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/strata/cli/generators/migration.rb', line 15

def create_migration_file
  timestamp = generate_timestamp
  filename = generate_filename(operation, entity, from, to, timestamp)
  output_path = File.join("migrations", filename)

  # Ensure directory exists
  empty_directory "migrations"

  # Load template and update with user inputs
  template_content = load_template(operation)
  hook = options[:hook] || ((operation == "swap") ? "post" : "pre")
  updated_content = update_template(template_content, hook)

  # Write the updated template
  create_file output_path, updated_content

  say_status :created, output_path, :green
end