Class: ActualDbSchema::SchemaDiff

Inherits:
Object
  • Object
show all
Includes:
OutputFormatter
Defined in:
lib/actual_db_schema/schema_diff.rb

Overview

Generates a diff of schema changes between the current schema file and the last committed version, annotated with the migrations responsible for each change.

Direct Known Subclasses

SchemaDiffHtml

Constant Summary collapse

SIGN_COLORS =
{
  "+" => :green,
  "-" => :red
}.freeze
CHANGE_PATTERNS =
{
  /t\.(\w+)\s+["']([^"']+)["']/ => :column,
  /t\.index\s+.*name:\s*["']([^"']+)["']/ => :index,
  /create_table\s+["']([^"']+)["']/ => :table
}.freeze

Constants included from OutputFormatter

OutputFormatter::UNICODE_COLORS

Instance Method Summary collapse

Methods included from OutputFormatter

#colorize

Constructor Details

#initialize(schema_path, migrations_path) ⇒ SchemaDiff

Returns a new instance of SchemaDiff.



22
23
24
25
# File 'lib/actual_db_schema/schema_diff.rb', line 22

def initialize(schema_path, migrations_path)
  @schema_path = schema_path
  @migrations_path = migrations_path
end

Instance Method Details

#renderObject



27
28
29
30
31
32
33
34
35
# File 'lib/actual_db_schema/schema_diff.rb', line 27

def render
  if old_schema_content.nil? || old_schema_content.strip.empty?
    puts colorize("Could not retrieve old schema from git.", :red)
    return
  end

  diff_output = generate_diff(old_schema_content, new_schema_content)
  process_diff_output(diff_output)
end