Module: JunglePath::Gen::SchemaTree
- Defined in:
- lib/jungle_path/gen/schema_tree.rb,
lib/jungle_path/gen/schema_tree/node.rb,
lib/jungle_path/gen/schema_tree/filter.rb,
lib/jungle_path/gen/schema_tree/match_tables.rb,
lib/jungle_path/gen/schema_tree/match_columns.rb,
lib/jungle_path/gen/schema_tree/match_table_data.rb
Defined Under Namespace
Classes: Filter, MatchColumns, MatchTableData, MatchTables, Node
Class Method Summary collapse
- .gen_node_tree(tables_hash, node_filter = nil) ⇒ Object
-
.test_node_filter ⇒ Object
configatron.schema.filters = { allow: [ “zztop”, /./, columns: nil, :contact, columns: [], :user, columns: /./, :opportunity, columns: :name ] deny: [ :xyz, columns: :zzz ] }.
Class Method Details
.gen_node_tree(tables_hash, node_filter = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/jungle_path/gen/schema_tree.rb', line 30 def self.gen_node_tree(tables_hash, node_filter=nil) # test node filter: ###node_filter = Gen.test_node_filter # create tree structure based on pk/fk releationships of tables. tables = tables_hash.values.sort {|a, b| a.table_name <=> b.table_name} root = JunglePath::Gen::SchemaTree::Node.new "root" root.tables_hash = {} tables.each do |v| #puts v.table_name.class #puts v.table_name next unless node_filter == nil || node_filter.allow?(v.table_name) # build tables hash: root.tables_hash[v.table_name] = v #puts v.table_name #puts "v.table_name: #{v.table_name}." table_node = JunglePath::Gen::SchemaTree::Node.new(v.table_name) root.nodes[v.table_name] = table_node # make sub nodes for each column columns = v.columns_sequence_order columns.each do |column| next unless node_filter == nil || node_filter.allow?(v.table_name, column.name) if column.foreign_key? name = column.name.to_s[0..-4].to_sym # cut off "..._id" from column name and use as node name. symbol = "->" child_table_name = column.foreign_key_table_name #puts "tables_hash: #{tables_hash}" #puts "column.foreign_key_table_name: #{column.foreign_key_table_name}" child_table_join_column_name = tables_hash[column.foreign_key_table_name].primary_key_columns.first[0] parent_table_join_column_name = column.name else name = column.name symbol = nil child_table_name = nil child_table_join_column_name = nil parent_table_join_column_name = nil end #puts " #{name}, symbol: #{symbol}." table_node.nodes[name] = JunglePath::Gen::SchemaTree::Node.new(name, symbol, child_table_name, child_table_join_column_name, parent_table_join_column_name) end # make sub nodes for each table having a fk reference to this (the parent) table -- exclude self. tables.each do |child_table| next unless node_filter == nil || node_filter.allow?(child_table.table_name) if v.table_name != child_table.table_name #nor own table fk_columns = child_table.foreign_key_columns_by_table_name[v.table_name] if fk_columns #puts " #{child_table.table_name}. count: #{fk_columns.count}." name = child_table.table_name table_node.nodes[name] = [] fk_columns.each do |key, fk_column| #puts " fk_column: #{fk_column.name}." #puts " name: #{name}, #{name.class}." #puts " class: #{table_node.nodes[name].class}." #puts " count: #{table_node.nodes[name].count}." if fk_column.primary_key? and child_table.primary_key_columns.count == 1 symbol = "<-" else symbol = "<=" end child_table_name = child_table.table_name child_table_join_column_name = fk_column.name parent_table_join_column_name = v.primary_key_columns.first[0] table_node.nodes[name] << JunglePath::Gen::SchemaTree::Node.new(name, symbol, child_table_name, child_table_join_column_name, parent_table_join_column_name) #puts " nodes[name].count: #{table_node.nodes[name].count}." end end end end end root end |
.test_node_filter ⇒ Object
configatron.schema.filters =
allow: [
{table: "zztop",
/./, columns: nil,
:contact, columns: [],
:user, columns: /./,
:opportunity, columns: :name
]
deny: [
:xyz, columns: :zzz
]
}
22 23 24 25 26 27 28 |
# File 'lib/jungle_path/gen/schema_tree.rb', line 22 def self.test_node_filter() JunglePath::Gen::SchemaTree::Filter.new(#{ #allow: [{table: /./}], #deny: [{table: /^siebel_/}] #} ) end |