Module: ActualDbSchema::MigrationParser

Extended by:
MigrationParser
Included in:
MigrationParser
Defined in:
lib/actual_db_schema/migration_parser.rb

Overview

Parses migration files in a Rails application into a structured hash representation.

Constant Summary collapse

PARSER_MAPPING =
{
  add_column: ->(args) { parse_add_column(args) },
  change_column: ->(args) { parse_change_column(args) },
  remove_column: ->(args) { parse_remove_column(args) },
  rename_column: ->(args) { parse_rename_column(args) },
  add_index: ->(args) { parse_add_index(args) },
  remove_index: ->(args) { parse_remove_index(args) },
  rename_index: ->(args) { parse_rename_index(args) },
  create_table: ->(args) { parse_create_table(args) },
  drop_table: ->(args) { parse_drop_table(args) }
}.freeze

Instance Method Summary collapse

Instance Method Details

#parse_all_migrations(dirs) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/actual_db_schema/migration_parser.rb', line 23

def parse_all_migrations(dirs)
  changes_by_path = {}
  handled_files = Set.new

  dirs.each do |dir|
    Dir["#{dir}/*.rb"].sort.each do |file|
      base_name = File.basename(file)
      next if handled_files.include?(base_name)

      changes = parse_file(file).yield_self { |ast| find_migration_changes(ast) }
      changes_by_path[file] = changes unless changes.empty?
      handled_files.add(base_name)
    end
  end

  changes_by_path
end