Django

Code

Changeset 7568

Show
Ignore:
Timestamp:
05/30/08 20:01:17 (6 months ago)
Author:
jacob
Message:

Fixed #6820: flush no longer fails under PostgreSQL 8.3. WARNING: In the process I renamed a couple of internal functions in django.core.management.sql, so this is a backwards-incompatible change if you were using those internal functions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/management/commands/syncdb.py

    r7294 r7568  
    2222        from django.db import connection, transaction, models 
    2323        from django.conf import settings 
    24         from django.core.management.sql import table_list, installed_models, sql_model_create, sql_for_pending_references, many_to_many_sql_for_model, custom_sql_for_model, sql_indexes_for_model, emit_post_sync_signal 
     24        from django.core.management.sql import table_names, installed_models, sql_model_create, sql_for_pending_references, many_to_many_sql_for_model, custom_sql_for_model, sql_indexes_for_model, emit_post_sync_signal 
    2525 
    2626        verbosity = int(options.get('verbosity', 1)) 
     
    4646        # Get a list of all existing database tables, so we know what needs to 
    4747        # be added. 
    48         tables = [table_name_converter(name) for name in table_list()] 
     48        tables = [table_name_converter(name) for name in table_names()] 
    4949 
    5050        # Get a list of already installed *models* so that references work right. 
  • django/trunk/django/core/management/sql.py

    r7477 r7568  
    88    from sets import Set as set   # Python 2.3 fallback 
    99 
    10 def table_list(): 
     10def table_names(): 
    1111    "Returns a list of all table names that exist in the database." 
    1212    from django.db import connection, get_introspection_module 
    1313    cursor = connection.cursor() 
    14     return get_introspection_module().get_table_list(cursor
    15  
    16 def django_table_list(only_existing=False): 
     14    return set(get_introspection_module().get_table_list(cursor)
     15 
     16def django_table_names(only_existing=False): 
    1717    """ 
    1818    Returns a list of all table names that have associated Django models and 
     
    2323    """ 
    2424    from django.db import models 
    25     tables = [] 
     25    tables = set() 
    2626    for app in models.get_apps(): 
    2727        for model in models.get_models(app): 
    28             tables.append(model._meta.db_table) 
    29             tables.extend([f.m2m_db_table() for f in model._meta.local_many_to_many]) 
     28            tables.add(model._meta.db_table) 
     29            tables.update([f.m2m_db_table() for f in model._meta.local_many_to_many]) 
    3030    if only_existing: 
    31         existing = table_list() 
    32         tables = [t for t in tables if t in existing] 
     31        tables = [t for t in tables if t in table_names()] 
    3332    return tables 
    3433 
     
    8382    app_models = models.get_models(app) 
    8483    final_output = [] 
    85     known_models = set([model for model in installed_models(table_list()) if model not in app_models]) 
     84    known_models = set([model for model in installed_models(table_names()) if model not in app_models]) 
    8685    pending_references = {} 
    8786 
     
    215214    from django.db import connection 
    216215    if only_django: 
    217         tables = django_table_list() 
     216        tables = django_table_names() 
    218217    else: 
    219         tables = table_list() 
     218        tables = table_names() 
    220219    statements = connection.ops.sql_flush(style, tables, sequence_list()) 
    221220    return statements