Class: ActualDbSchema::SchemaDiff
- Inherits:
-
Object
- Object
- ActualDbSchema::SchemaDiff
- 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
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
-
#initialize(schema_path, migrations_path) ⇒ SchemaDiff
constructor
A new instance of SchemaDiff.
- #render ⇒ Object
Methods included from OutputFormatter
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
#render ⇒ Object
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 |