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.

Constant Summary

Constants included from Output

Output::THEME

Instance Method Summary collapse

Methods inherited from Group

exit_on_failure?, source_root

Methods included from Output

format, pastel, print_error, #print_error, print_hint, #print_hint, print_info, #print_info, print_status, #print_status, print_success, #print_success, print_warning, #print_warning, shell_for, thor_color

Instance Method Details

#create_migration_fileObject



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

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

  Output.print_status(:created, output_path, type: :success, context: self)
end