summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2014-12-26 13:56:08 -0500
committerTim Graham <timograham@gmail.com>2015-01-17 10:16:06 -0500
commit4aa089a9a9504c4a833eee8161be013206da5d15 (patch)
treeebc7e23d3805c57d9f6a4fc75767b5e5046617a4 /django
parenta420f83e7d2e446ca01ef7c13d30c2ef3e975e5c (diff)
Removed support for custom SQL per deprecation timeline.
Diffstat (limited to 'django')
-rw-r--r--django/core/management/__init__.py2
-rw-r--r--django/core/management/commands/inspectdb.py3
-rw-r--r--django/core/management/commands/migrate.py56
-rw-r--r--django/core/management/commands/sqlall.py2
-rw-r--r--django/core/management/commands/sqlcustom.py24
-rw-r--r--django/core/management/sql.py58
-rw-r--r--django/db/backends/base/creation.py1
7 files changed, 4 insertions, 142 deletions
diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py
index ed4323ecd0..5532a0e3e9 100644
--- a/django/core/management/__init__.py
+++ b/django/core/management/__init__.py
@@ -233,7 +233,7 @@ class ManagementUtility(object):
subcommand_cls = self.fetch_command(cwords[0])
# special case: add the names of installed apps to options
if cwords[0] in ('dumpdata', 'sql', 'sqlall', 'sqlclear',
- 'sqlcustom', 'sqlindexes', 'sqlmigrate', 'sqlsequencereset', 'test'):
+ 'sqlindexes', 'sqlmigrate', 'sqlsequencereset', 'test'):
try:
app_configs = apps.get_app_configs()
# Get the last part of the dotted path as the app name.
diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py
index abe62c4c1f..e433e62854 100644
--- a/django/core/management/commands/inspectdb.py
+++ b/django/core/management/commands/inspectdb.py
@@ -45,9 +45,6 @@ class Command(BaseCommand):
"Django to create, modify, and delete the table"
)
yield "# Feel free to rename the models, but don't rename db_table values or field names."
- yield "#"
- yield "# Also note: You'll have to insert the output of 'django-admin sqlcustom [app_label]'"
- yield "# into your database."
yield "from __future__ import unicode_literals"
yield ''
yield 'from %s import models' % self.db_module
diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py
index 54d3617368..6e5640eac2 100644
--- a/django/core/management/commands/migrate.py
+++ b/django/core/management/commands/migrate.py
@@ -4,14 +4,12 @@ from __future__ import unicode_literals
from collections import OrderedDict
from importlib import import_module
import time
-import traceback
import warnings
from django.apps import apps
from django.core.management import call_command
from django.core.management.base import BaseCommand, CommandError
-from django.core.management.color import no_style
-from django.core.management.sql import custom_sql_for_model, emit_post_migrate_signal, emit_pre_migrate_signal
+from django.core.management.sql import emit_post_migrate_signal, emit_pre_migrate_signal
from django.db import connections, router, transaction, DEFAULT_DB_ALIAS
from django.db.migrations.executor import MigrationExecutor
from django.db.migrations.loader import AmbiguityError
@@ -47,7 +45,6 @@ class Command(BaseCommand):
self.verbosity = options.get('verbosity')
self.interactive = options.get('interactive')
- self.show_traceback = options.get('traceback')
# Import the 'management' module within each installed app, to register
# dispatcher events.
@@ -73,7 +70,7 @@ class Command(BaseCommand):
no_color=options.get('no_color'),
settings=options.get('settings'),
stdout=self.stdout,
- traceback=self.show_traceback,
+ traceback=options.get('traceback'),
verbosity=self.verbosity,
)
@@ -167,18 +164,6 @@ class Command(BaseCommand):
self.stdout.write(self.style.MIGRATE_HEADING("Synchronizing apps without migrations:"))
self.sync_apps(connection, executor.loader.unmigrated_apps)
- # The test runner requires us to flush after a syncdb but before migrations,
- # so do that here.
- if options.get("test_flush", False):
- call_command(
- 'flush',
- verbosity=max(self.verbosity - 1, 0),
- interactive=False,
- database=db,
- reset_sequences=False,
- inhibit_post_migrate=True,
- )
-
# Migrate!
if self.verbosity >= 1:
self.stdout.write(self.style.MIGRATE_HEADING("Running migrations:"))
@@ -299,41 +284,4 @@ class Command(BaseCommand):
finally:
cursor.close()
- # The connection may have been closed by a syncdb handler.
- cursor = connection.cursor()
- try:
- # Install custom SQL for the app (but only if this
- # is a model we've just created)
- if self.verbosity >= 1:
- self.stdout.write(" Installing custom SQL...\n")
- for app_name, model_list in manifest.items():
- for model in model_list:
- if model in created_models:
- custom_sql = custom_sql_for_model(model, no_style(), connection)
- if custom_sql:
- if self.verbosity >= 2:
- self.stdout.write(
- " Installing custom SQL for %s.%s model\n" %
- (app_name, model._meta.object_name)
- )
- try:
- with transaction.atomic(using=connection.alias):
- for sql in custom_sql:
- cursor.execute(sql)
- except Exception as e:
- self.stderr.write(
- " Failed to install custom SQL for %s.%s model: %s\n"
- % (app_name, model._meta.object_name, e)
- )
- if self.show_traceback:
- traceback.print_exc()
- else:
- if self.verbosity >= 3:
- self.stdout.write(
- " No custom SQL for %s.%s model\n" %
- (app_name, model._meta.object_name)
- )
- finally:
- cursor.close()
-
return created_models
diff --git a/django/core/management/commands/sqlall.py b/django/core/management/commands/sqlall.py
index e7d7d0564d..d58ac4bf8f 100644
--- a/django/core/management/commands/sqlall.py
+++ b/django/core/management/commands/sqlall.py
@@ -6,7 +6,7 @@ from django.db import connections, DEFAULT_DB_ALIAS
class Command(AppCommand):
- help = "Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the given model module name(s)."
+ help = "Prints the CREATE TABLE and CREATE INDEX SQL statements for the given model module name(s)."
output_transaction = True
diff --git a/django/core/management/commands/sqlcustom.py b/django/core/management/commands/sqlcustom.py
deleted file mode 100644
index 84f213ca60..0000000000
--- a/django/core/management/commands/sqlcustom.py
+++ /dev/null
@@ -1,24 +0,0 @@
-from __future__ import unicode_literals
-
-from django.core.management.base import AppCommand
-from django.core.management.sql import sql_custom
-from django.db import connections, DEFAULT_DB_ALIAS
-
-
-class Command(AppCommand):
- help = "Prints the custom table modifying SQL statements for the given app name(s)."
-
- output_transaction = True
-
- def add_arguments(self, parser):
- super(Command, self).add_arguments(parser)
- parser.add_argument('--database', default=DEFAULT_DB_ALIAS,
- help='Nominates a database to print the SQL for. Defaults to the '
- '"default" database.')
-
- def handle_app_config(self, app_config, **options):
- if app_config.models_module is None:
- return
- connection = connections[options['database']]
- statements = sql_custom(app_config, self.style, connection)
- return '\n'.join(statements)
diff --git a/django/core/management/sql.py b/django/core/management/sql.py
index c38993e702..2c70630ad7 100644
--- a/django/core/management/sql.py
+++ b/django/core/management/sql.py
@@ -1,15 +1,10 @@
from __future__ import unicode_literals
-import io
-import os
import re
-import warnings
from django.apps import apps
-from django.conf import settings
from django.core.management.base import CommandError
from django.db import models, router
-from django.utils.deprecation import RemovedInDjango19Warning
from django.utils.version import get_docs_version
@@ -140,21 +135,6 @@ def sql_flush(style, connection, only_django=False, reset_sequences=True, allow_
return statements
-def sql_custom(app_config, style, connection):
- "Returns a list of the custom table modifying SQL statements for the given app."
-
- check_for_migrations(app_config, connection)
-
- output = []
-
- app_models = router.get_migratable_models(app_config, connection.alias)
-
- for model in app_models:
- output.extend(custom_sql_for_model(model, style, connection))
-
- return output
-
-
def sql_indexes(app_config, style, connection):
"Returns a list of the CREATE INDEX SQL statements for all models in the given app."
@@ -184,7 +164,6 @@ def sql_all(app_config, style, connection):
"Returns a list of CREATE TABLE SQL, initial-data inserts, and CREATE INDEX SQL for the given module."
return (
sql_create(app_config, style, connection) +
- sql_custom(app_config, style, connection) +
sql_indexes(app_config, style, connection)
)
@@ -205,43 +184,6 @@ def _split_statements(content):
return statements
-def custom_sql_for_model(model, style, connection):
- opts = model._meta
- app_dirs = []
- app_dir = apps.get_app_config(model._meta.app_label).path
- app_dirs.append(os.path.normpath(os.path.join(app_dir, 'sql')))
-
- # Deprecated location -- remove in Django 1.9
- old_app_dir = os.path.normpath(os.path.join(app_dir, 'models/sql'))
- if os.path.exists(old_app_dir):
- warnings.warn("Custom SQL location '<app_label>/models/sql' is "
- "deprecated, use '<app_label>/sql' instead.",
- RemovedInDjango19Warning)
- app_dirs.append(old_app_dir)
-
- output = []
-
- # Post-creation SQL should come before any initial SQL data is loaded.
- # However, this should not be done for models that are unmanaged or
- # for fields that are part of a parent model (via model inheritance).
- if opts.managed:
- post_sql_fields = [f for f in opts.local_fields if hasattr(f, 'post_create_sql')]
- for f in post_sql_fields:
- output.extend(f.post_create_sql(style, model._meta.db_table))
-
- # Find custom SQL, if it's available.
- backend_name = connection.settings_dict['ENGINE'].split('.')[-1]
- sql_files = []
- for app_dir in app_dirs:
- sql_files.append(os.path.join(app_dir, "%s.%s.sql" % (opts.model_name, backend_name)))
- sql_files.append(os.path.join(app_dir, "%s.sql" % opts.model_name))
- for sql_file in sql_files:
- if os.path.exists(sql_file):
- with io.open(sql_file, encoding=settings.FILE_CHARSET) as fp:
- output.extend(connection.ops.prepare_sql_script(fp.read(), _allow_fallback=True))
- return output
-
-
def emit_pre_migrate_signal(verbosity, interactive, db):
# Emit the pre_migrate signal for every application.
for app_config in apps.get_app_configs():
diff --git a/django/db/backends/base/creation.py b/django/db/backends/base/creation.py
index 5044fcfb6c..b3609dbb95 100644
--- a/django/db/backends/base/creation.py
+++ b/django/db/backends/base/creation.py
@@ -366,7 +366,6 @@ class BaseDatabaseCreation(object):
verbosity=max(verbosity - 1, 0),
interactive=False,
database=self.connection.alias,
- test_flush=True,
)
# We then serialize the current state of the database into a string