(self, style, tables, *, reset_sequences=False, allow_cascade=False)
| 457 | return lru_cache(maxsize=512)(self.__foreign_key_constraints) |
| 458 | |
| 459 | def sql_flush(self, style, tables, *, reset_sequences=False, allow_cascade=False): |
| 460 | if not tables: |
| 461 | return [] |
| 462 | |
| 463 | truncated_tables = {table.upper() for table in tables} |
| 464 | constraints = set() |
| 465 | # Oracle's TRUNCATE CASCADE only works with ON DELETE CASCADE foreign |
| 466 | # keys which Django doesn't define. Emulate the PostgreSQL behavior |
| 467 | # which truncates all dependent tables by manually retrieving all |
| 468 | # foreign key constraints and resolving dependencies. |
| 469 | for table in tables: |
| 470 | for foreign_table, constraint in self._foreign_key_constraints( |
| 471 | table, recursive=allow_cascade |
| 472 | ): |
| 473 | if allow_cascade: |
| 474 | truncated_tables.add(foreign_table) |
| 475 | constraints.add((foreign_table, constraint)) |
| 476 | sql = ( |
| 477 | [ |
| 478 | "%s %s %s %s %s %s %s %s;" |
| 479 | % ( |
| 480 | style.SQL_KEYWORD("ALTER"), |
| 481 | style.SQL_KEYWORD("TABLE"), |
| 482 | style.SQL_FIELD(self.quote_name(table)), |
| 483 | style.SQL_KEYWORD("DISABLE"), |
| 484 | style.SQL_KEYWORD("CONSTRAINT"), |
| 485 | style.SQL_FIELD(self.quote_name(constraint)), |
| 486 | style.SQL_KEYWORD("KEEP"), |
| 487 | style.SQL_KEYWORD("INDEX"), |
| 488 | ) |
| 489 | for table, constraint in constraints |
| 490 | ] |
| 491 | + [ |
| 492 | "%s %s %s;" |
| 493 | % ( |
| 494 | style.SQL_KEYWORD("TRUNCATE"), |
| 495 | style.SQL_KEYWORD("TABLE"), |
| 496 | style.SQL_FIELD(self.quote_name(table)), |
| 497 | ) |
| 498 | for table in truncated_tables |
| 499 | ] |
| 500 | + [ |
| 501 | "%s %s %s %s %s %s;" |
| 502 | % ( |
| 503 | style.SQL_KEYWORD("ALTER"), |
| 504 | style.SQL_KEYWORD("TABLE"), |
| 505 | style.SQL_FIELD(self.quote_name(table)), |
| 506 | style.SQL_KEYWORD("ENABLE"), |
| 507 | style.SQL_KEYWORD("CONSTRAINT"), |
| 508 | style.SQL_FIELD(self.quote_name(constraint)), |
| 509 | ) |
| 510 | for table, constraint in constraints |
| 511 | ] |
| 512 | ) |
| 513 | if reset_sequences: |
| 514 | sequences = [ |
| 515 | sequence |
| 516 | for sequence in self.connection.introspection.sequence_list() |
nothing calls this directly
no test coverage detected