Class: Strata::CLI::SubCommands::Create

Inherits:
Thor
  • Object
show all
Extended by:
Helpers::DescriptionHelper
Includes:
AgentMode, Guard, Helpers::CommandContext, Prompts, Terminal, Thor::Actions
Defined in:
lib/strata/cli/sub_commands/create.rb

Constant Summary

Constants included from DatasourceHelper

DatasourceHelper::ADAPTER_DRIVER_GEMS

Constants included from Output

Output::THEME

Constants included from Prompts

Prompts::MIGRATION_HOOK_OPTIONS, Prompts::MSG_CONTINUE_NO_FIELDS, Prompts::MSG_CREATED_MODEL, Prompts::MSG_EDIT_MODEL_HINT, Prompts::MSG_FIELDS_CONFIRMED, Prompts::MSG_JOIN_CONDITION, Prompts::MSG_MODELS_COUNT, Prompts::MSG_MODELS_LIST_HEADER, Prompts::MSG_MODEL_DESCRIPTION, Prompts::MSG_MODEL_DISPLAY_NAME, Prompts::MSG_NO_FIELDS_CONFIRMED, Prompts::MSG_NO_MODELS_DIR, Prompts::MSG_NO_MODELS_FOUND, Prompts::MSG_NO_TABLES_FOUND, Prompts::MSG_RELATION_PATH, Prompts::MSG_SEARCH_TABLE, Prompts::MSG_SELECT_FROM_LIST, Prompts::MSG_SELECT_LEFT_TABLE, Prompts::MSG_SELECT_RIGHT_TABLE_ALL, Prompts::MSG_SELECT_RIGHT_TABLE_SUGGESTED, Prompts::MSG_SHOW_OTHER_TABLES

Constants included from Guard

Guard::ALLOWED_COMMANDS

Instance Method Summary collapse

Methods included from Helpers::DescriptionHelper

long_desc_from_file

Methods included from AgentMode

#agent_mode?, included, #reject_agent_mode!

Methods included from Helpers::CommandContext

#adapter, #all_tables, #datasource_key, #prompt, #table_fetch_result

Methods included from DatasourceHelper

#apply_readonly_mode, #create_adapter, #ds_config, #ensure_adapter_driver_gems!, #load_adapter_driver_gems!, #resolve_datasource, #resolve_datasource_value

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

Methods included from Prompts

default_migration_hook

Methods included from Terminal

#create_spinner, #print_table, #with_spinner

Methods included from Guard

#invoke_command

Instance Method Details

#migration(subcommand) ⇒ Object



80
81
82
83
84
85
86
87
88
89
# File 'lib/strata/cli/sub_commands/create.rb', line 80

def migration(subcommand)
  case subcommand
  when "rename"
    migration_rename
  when "swap"
    migration_swap
  else
    raise Strata::CommandError, "Unknown migration subcommand: #{subcommand}. Use 'rename' or 'swap'."
  end
end

#migration_renameObject



99
100
101
102
103
104
105
# File 'lib/strata/cli/sub_commands/create.rb', line 99

def migration_rename
  validate_entity_type(options[:entity], "rename")
  validate_required_params(options[:entity], options[:from], options[:to])

  hook = prompt_migration_hook("rename")
  create_rename_migration(options[:entity], options[:from], options[:to], hook)
end

#migration_swapObject



115
116
117
118
119
120
121
# File 'lib/strata/cli/sub_commands/create.rb', line 115

def migration_swap
  validate_entity_type(options[:entity], "swap")
  validate_required_params(options[:entity], options[:from], options[:to])

  hook = prompt_migration_hook("swap")
  create_swap_migration(options[:entity], options[:from], options[:to], hook)
end

#relation(relation_path) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/strata/cli/sub_commands/create.rb', line 60

def relation(relation_path)
  reject_agent_mode!(
    "Agent mode: write models/rel.*.yml directly.",
    code: "use_yaml_files"
  )

  return unless datasource_key

  create_relation_file(relation_path)
end

#table(table_path = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/strata/cli/sub_commands/create.rb', line 38

def table(table_path = nil)
  reject_agent_mode!(
    "Agent mode: write models/tbl.*.yml directly. Use: strata datasource meta DS_KEY TABLE_NAME --agent",
    code: "use_yaml_files"
  )

  return unless datasource_key

  # If table_path provided, skip search for speed
  if table_path
    handle_table_creation_with_path(table_path)
  else
    handle_table_creation_interactive
  end
end