Class: Pcrd::Schema::Differ

Inherits:
Object
  • Object
show all
Defined in:
lib/pcrd/schema/differ.rb

Overview

Computes the diff between source and target schemas, optionally guided by a migration spec (Config::Table).

Two modes:

Synthesis mode (target_columns: nil)
  The target schema is synthesized by applying the migration spec to the
  source columns. Use this to preview what the target will look like before
  the migration has run.

Real-target mode (target_columns: [...])
  The target schema comes from a live database query. The spec is used
  to understand source→target column name mappings; without a spec,
  columns are matched by name.

Instance Method Summary collapse

Instance Method Details

#diff(source_columns:, table_config: nil, target_columns: nil) ⇒ Object

Returns Array<DiffEntry> in source-column order, added columns last.

source_columns: Array<Schema::Column> table_config: Config::Table or nil target_columns: Array<Schema::Column> or nil (triggers synthesis)



27
28
29
30
31
32
33
# File 'lib/pcrd/schema/differ.rb', line 27

def diff(source_columns:, table_config: nil, target_columns: nil)
  if target_columns.nil?
    synthesize_diff(source_columns, table_config)
  else
    real_diff(source_columns, table_config, target_columns)
  end
end

#target_columns_from_diff(entries) ⇒ Object

Extracts target-side columns from a diff for use in padding analysis.



36
37
38
39
40
41
# File 'lib/pcrd/schema/differ.rb', line 36

def target_columns_from_diff(entries)
  entries
    .reject(&:dropped?)
    .map(&:target_column)
    .compact
end