| 1 |
import sys |
| 2 |
|
| 3 |
from django.apps import apps |
| 4 |
from django.db import models |
| 5 |
|
| 6 |
|
| 7 |
def sql_flush(style, connection, reset_sequences=True, allow_cascade=False): |
| 8 |
""" |
| 9 |
Return a list of the SQL statements used to flush the database. |
| 10 |
""" |
| 11 |
tables = connection.introspection.django_table_names( |
| 12 |
only_existing=True, include_views=False |
| 13 |
) |
| 14 |
return connection.ops.sql_flush( |
| 15 |
style, |
| 16 |
tables, |
| 17 |
reset_sequences=reset_sequences, |
| 18 |
allow_cascade=allow_cascade, |
| 19 |
) |
| 20 |
|
| 21 |
|
| 22 |
def emit_pre_migrate_signal(verbosity, interactive, db, **kwargs): |
| 23 |
# Emit the pre_migrate signal for every application. |
| 24 |
for app_config in apps.get_app_configs(): |
| 25 |
if app_config.models_module is None: |
| 26 |
continue |
| 27 |
if verbosity >= 2: |
| 28 |
stdout = kwargs.get("stdout", sys.stdout) |
| 29 |
stdout.write( |
| 30 |
"Running pre-migrate handlers for application %s" % app_config.label |
| 31 |
) |
| 32 |
models.signals.pre_migrate.send( |
| 33 |
sender=app_config, |
| 34 |
app_config=app_config, |
| 35 |
verbosity=verbosity, |
| 36 |
interactive=interactive, |
| 37 |
using=db, |
| 38 |
**kwargs, |
| 39 |
) |
| 40 |
|
| 41 |
|
| 42 |
def emit_post_migrate_signal(verbosity, interactive, db, **kwargs): |
| 43 |
# Emit the post_migrate signal for every application. |
| 44 |
for app_config in apps.get_app_configs(): |
| 45 |
if app_config.models_module is None: |
| 46 |
continue |
| 47 |
if verbosity >= 2: |
| 48 |
stdout = kwargs.get("stdout", sys.stdout) |
| 49 |
stdout.write( |
| 50 |
"Running post-migrate handlers for application %s" % app_config.label |
| 51 |
) |
| 52 |
models.signals.post_migrate.send( |
| 53 |
sender=app_config, |
| 54 |
app_config=app_config, |
| 55 |
verbosity=verbosity, |
| 56 |
interactive=interactive, |
| 57 |
using=db, |
| 58 |
**kwargs, |
| 59 |
) |