def compute_dependencies(tables):
 tables = list(tables)
 graph = {}
 def visit_foreign_key(fkey):
  if fkey.use_alter:
   return
  parent_table = fkey.column.table
  if (parent_table in tables):
   child_table = fkey.parent.table
   if (parent_table is not child_table):
    graph.setdefault(parent_table, []).append(child_table)
 for table in tables:
  visitors.traverse(table, {'schema_visitor': True}, {'foreign_key': visit_foreign_key})
  graph.setdefault(table, []).extend(table._extra_dependencies)
 return graph

def compute_dependencies ( tables ) : tables = list ( tables ) graph = { } def visit_foreign_key ( fkey ) : if fkey . use_alter : return parent_table = fkey . column . table if ( parent_table in tables ) : child_table = fkey . parent . table if ( parent_table is not child_table ) : graph . setdefault ( parent_table , [ ] ) . append ( child_table ) for table in tables : visitors . traverse ( table , { 'schema_visitor' : True } , { 'foreign_key' : visit_foreign_key } ) graph . setdefault ( table , [ ] ) . extend ( table . _extra_dependencies ) return graph
construct a reverse dependency graph for the given tables .