| 1345 | |
| 1346 | |
| 1347 | class SchemaGenerator(InvokeCreateDDLBase): |
| 1348 | def __init__( |
| 1349 | self, |
| 1350 | dialect, |
| 1351 | connection, |
| 1352 | checkfirst=CheckFirst.NONE, |
| 1353 | tables=None, |
| 1354 | **kwargs, |
| 1355 | ): |
| 1356 | super().__init__(connection, **kwargs) |
| 1357 | self.checkfirst = CheckFirst(checkfirst) |
| 1358 | self.tables = tables |
| 1359 | self.preparer = dialect.identifier_preparer |
| 1360 | self.dialect = dialect |
| 1361 | self.memo = {} |
| 1362 | |
| 1363 | def _can_create_table(self, table): |
| 1364 | self.dialect.validate_identifier(table.name) |
| 1365 | effective_schema = self.connection.schema_for_object(table) |
| 1366 | if effective_schema: |
| 1367 | self.dialect.validate_identifier(effective_schema) |
| 1368 | |
| 1369 | bool_to_check = ( |
| 1370 | CheckFirst.TABLES if not table.is_view else CheckFirst.VIEWS |
| 1371 | ) |
| 1372 | return ( |
| 1373 | not self.checkfirst & bool_to_check |
| 1374 | or not self.dialect.has_table( |
| 1375 | self.connection, table.name, schema=effective_schema |
| 1376 | ) |
| 1377 | ) |
| 1378 | |
| 1379 | def _can_create_index(self, index): |
| 1380 | effective_schema = self.connection.schema_for_object(index.table) |
| 1381 | if effective_schema: |
| 1382 | self.dialect.validate_identifier(effective_schema) |
| 1383 | return ( |
| 1384 | not self.checkfirst & CheckFirst.INDEXES |
| 1385 | or not self.dialect.has_index( |
| 1386 | self.connection, |
| 1387 | index.table.name, |
| 1388 | index.name, |
| 1389 | schema=effective_schema, |
| 1390 | ) |
| 1391 | ) |
| 1392 | |
| 1393 | def _can_create_sequence(self, sequence): |
| 1394 | effective_schema = self.connection.schema_for_object(sequence) |
| 1395 | |
| 1396 | return self.dialect.supports_sequences and ( |
| 1397 | (not self.dialect.sequences_optional or not sequence.optional) |
| 1398 | and ( |
| 1399 | not self.checkfirst & CheckFirst.SEQUENCES |
| 1400 | or not self.dialect.has_sequence( |
| 1401 | self.connection, sequence.name, schema=effective_schema |
| 1402 | ) |
| 1403 | ) |
| 1404 | ) |
no outgoing calls