Changed [735] so that database-agnostic SQL always gets executed, even if database-specific SQL doesn't exist.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@737 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-09-29 23:43:03 +00:00
parent 27b1f69d79
commit 998fc72c0d
1 changed files with 10 additions and 16 deletions

View File

@ -156,29 +156,23 @@ get_sql_reset.args = APP_ARGS
def get_sql_initial_data(mod): def get_sql_initial_data(mod):
"Returns a list of the initial INSERT SQL statements for the given module." "Returns a list of the initial INSERT SQL statements for the given module."
from django.core import db
output = [] output = []
app_label = mod._MODELS[0]._meta.app_label app_label = mod._MODELS[0]._meta.app_label
output.append(_get_packages_insert(app_label)) output.append(_get_packages_insert(app_label))
app_dir = os.path.normpath(os.path.join(os.path.dirname(mod.__file__), '../sql')) app_dir = os.path.normpath(os.path.join(os.path.dirname(mod.__file__), '../sql'))
for klass in mod._MODELS: for klass in mod._MODELS:
opts = klass._meta opts = klass._meta
# Add custom SQL, if it's available. # Add custom SQL, if it's available.
from django.core import db sql_files = [os.path.join(app_dir, opts.module_name + '.' + db.DATABASE_ENGINE + '.sql'),
os.path.join(app_dir, opts.module_name + '.sql')]
# Get the sql file name for the init data for the current database engine for sql_file in sql_files:
db_engine_sql_file_name = os.path.join(app_dir, opts.module_name + '.' + db.DATABASE_ENGINE.lower() + '.sql') if os.path.exists(sql_file):
fp = open(sql_file)
# Check if the data specific file exists
if os.path.exists(db_engine_sql_file_name):
sql_file_name = db_engine_sql_file_name
# if the database specific file doesn't exist, use the database agnostic version
else:
sql_file_name = os.path.join(app_dir, opts.module_name + '.sql')
if os.path.exists(sql_file_name):
fp = open(sql_file_name, 'r')
output.append(fp.read()) output.append(fp.read())
fp.close() fp.close()
# Content types. # Content types.
output.append(_get_contenttype_insert(opts)) output.append(_get_contenttype_insert(opts))
# Permissions. # Permissions.