22from app .inspector import service as inspector
33
44
5- def make (collector , * args , ** kwargs ): # noqa: C901
5+ def make (collector , logger = None , * args , ** kwargs ): # noqa: C901
66 """We take an initial pass at making the definition based on the OID, if supported. The collector
77 marks the raw database object as "processed" if we are able to match it to a Django model instance.
88 """
@@ -14,6 +14,9 @@ def make(collector, *args, **kwargs): # noqa: C901
1414 for number , row in enumerate (inspector .tables_and_views (collector .datastore )):
1515 schema_name = row .pop ('table_schema' )
1616
17+ if logger and schema_name != last_schema_name :
18+ logger .info ('Starting to process schema: %s' , schema_name )
19+
1720 if schema_name not in definition :
1821 schema_instance = collector .schemas .find_by_oid (row ['schema_object_id' ])
1922
@@ -74,42 +77,42 @@ def make(collector, *args, **kwargs): # noqa: C901
7477 'indexes' : indexes ,
7578 })
7679
77- schema = definition [schema_name ]['schema' ]
80+ if number > 0 and last_schema_name != schema_name :
81+ schema = definition [last_schema_name ]['schema' ]
7882
79- if not schema ['instance' ]:
80- schema ['instance' ] = collector .schemas .search_unassigned (name = schema ['name' ])
83+ if not schema ['instance' ]:
84+ schema ['instance' ] = collector .schemas .search_unassigned (name = schema ['name' ])
8185
82- if schema ['instance' ]:
83- collector .schemas .mark_as_processed (schema ['instance' ].pk )
86+ if schema ['instance' ]:
87+ collector .schemas .mark_as_processed (schema ['instance' ].pk )
8488
85- for table in definition [schema_name ]['tables' ]:
86- if not table ['instance' ] and schema ['instance' ]:
87- table ['instance' ] = collector .tables .search_unassigned (name = table ['name' ], schema_id = schema ['instance' ].pk )
89+ for table in definition [last_schema_name ]['tables' ]:
90+ if not table ['instance' ] and schema ['instance' ]:
91+ table ['instance' ] = collector .tables .search_unassigned (name = table ['name' ], schema_id = schema ['instance' ].pk )
8892
89- if not table ['instance' ]:
90- continue
93+ if not table ['instance' ]:
94+ continue
9195
92- collector .tables .mark_as_processed (table ['instance' ].pk )
96+ collector .tables .mark_as_processed (table ['instance' ].pk )
9397
94- for column in table ['columns' ]:
95- if column ['instance' ]:
96- continue
98+ for column in table ['columns' ]:
99+ if column ['instance' ]:
100+ continue
97101
98- column ['instance' ] = collector .columns .search_unassigned (name = column ['name' ], table_id = table ['instance' ].pk )
102+ column ['instance' ] = collector .columns .search_unassigned (name = column ['name' ], table_id = table ['instance' ].pk )
99103
100- if column ['instance' ]:
101- collector .columns .mark_as_processed (column ['instance' ].pk )
104+ if column ['instance' ]:
105+ collector .columns .mark_as_processed (column ['instance' ].pk )
102106
103- for index in table ['indexes' ]:
104- if index ['instance' ]:
105- continue
107+ for index in table ['indexes' ]:
108+ if index ['instance' ]:
109+ continue
106110
107- index ['instance' ] = collector .indexes .search_unassigned (name = index ['name' ], table_id = table ['instance' ].pk )
111+ index ['instance' ] = collector .indexes .search_unassigned (name = index ['name' ], table_id = table ['instance' ].pk )
108112
109- if index ['instance' ]:
110- collector .indexes .mark_as_processed (index ['instance' ].pk )
113+ if index ['instance' ]:
114+ collector .indexes .mark_as_processed (index ['instance' ].pk )
111115
112- if number > 0 and last_schema_name != schema_name :
113116 yield (last_schema_name , definition .pop (last_schema_name ))
114117
115118 last_schema_name = schema_name
0 commit comments