Class: Pinspec::SchemaGraph

Inherits:
Data
  • Object
show all
Defined in:
lib/pinspec/types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fk_mapObject (readonly)

Returns the value of attribute fk_map

Returns:

  • (Object)

    the current value of fk_map



468
469
470
# File 'lib/pinspec/types.rb', line 468

def fk_map
  @fk_map
end

#foreign_keysObject (readonly)

Returns the value of attribute foreign_keys

Returns:

  • (Object)

    the current value of foreign_keys



468
469
470
# File 'lib/pinspec/types.rb', line 468

def foreign_keys
  @foreign_keys
end

#skipped_statementsObject (readonly)

Returns the value of attribute skipped_statements

Returns:

  • (Object)

    the current value of skipped_statements



468
469
470
# File 'lib/pinspec/types.rb', line 468

def skipped_statements
  @skipped_statements
end

#tablesObject (readonly)

Returns the value of attribute tables

Returns:

  • (Object)

    the current value of tables



468
469
470
# File 'lib/pinspec/types.rb', line 468

def tables
  @tables
end

Instance Method Details

#annotate_relevance(planned_tables) ⇒ Object



489
490
491
492
493
494
495
# File 'lib/pinspec/types.rb', line 489

def annotate_relevance(planned_tables)
  wanted = Array(planned_tables).map(&:to_s)

  with(skipped_statements: skipped_statements.map do |statement|
    statement.with(relevant: statement.tables_touched.any? { |t| wanted.include?(t) })
  end)
end

#fk_for(table_name, column_name) ⇒ Object



477
478
479
# File 'lib/pinspec/types.rb', line 477

def fk_for(table_name, column_name)
  foreign_keys.find { |fk| fk.from_table == table_name.to_s && fk.column == column_name.to_s }
end

#foreign_keys_from(table_name) ⇒ Object



481
482
483
# File 'lib/pinspec/types.rb', line 481

def foreign_keys_from(table_name)
  foreign_keys.select { |fk| fk.from_table == table_name.to_s }
end

#table(name) ⇒ Object



469
470
471
# File 'lib/pinspec/types.rb', line 469

def table(name)
  tables.find { |t| t.name == name.to_s }
end

#table_namesObject



473
474
475
# File 'lib/pinspec/types.rb', line 473

def table_names
  tables.map(&:name)
end

#unknown_columnsObject



485
486
487
# File 'lib/pinspec/types.rb', line 485

def unknown_columns
  tables.flat_map { |t| t.columns.select(&:unknown_type?).map { |c| [t.name, c] } }
end