You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sql.py 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from django.apps import apps
  2. from django.db import models
  3. def sql_flush(style, connection, only_django=False, reset_sequences=True, allow_cascade=False):
  4. """
  5. Return a list of the SQL statements used to flush the database.
  6. If only_django is True, only include the table names that have associated
  7. Django models and are in INSTALLED_APPS .
  8. """
  9. if only_django:
  10. tables = connection.introspection.django_table_names(only_existing=True, include_views=False)
  11. else:
  12. tables = connection.introspection.table_names(include_views=False)
  13. seqs = connection.introspection.sequence_list() if reset_sequences else ()
  14. statements = connection.ops.sql_flush(style, tables, seqs, allow_cascade)
  15. return statements
  16. def emit_pre_migrate_signal(verbosity, interactive, db, **kwargs):
  17. # Emit the pre_migrate signal for every application.
  18. for app_config in apps.get_app_configs():
  19. if app_config.models_module is None:
  20. continue
  21. if verbosity >= 2:
  22. print("Running pre-migrate handlers for application %s" % app_config.label)
  23. models.signals.pre_migrate.send(
  24. sender=app_config,
  25. app_config=app_config,
  26. verbosity=verbosity,
  27. interactive=interactive,
  28. using=db,
  29. **kwargs
  30. )
  31. def emit_post_migrate_signal(verbosity, interactive, db, **kwargs):
  32. # Emit the post_migrate signal for every application.
  33. for app_config in apps.get_app_configs():
  34. if app_config.models_module is None:
  35. continue
  36. if verbosity >= 2:
  37. print("Running post-migrate handlers for application %s" % app_config.label)
  38. models.signals.post_migrate.send(
  39. sender=app_config,
  40. app_config=app_config,
  41. verbosity=verbosity,
  42. interactive=interactive,
  43. using=db,
  44. **kwargs
  45. )