Ticket #3053: django_clear.patch

File django_clear.patch, 2.9 KB (added by Zoltan Arokszallasi <godri@…>, 18 years ago)
  • core/management.py

    diff -ruN django.branch/core/management.py django/core/management.py
    old new  
    273273def get_sql_delete(app):
    274274    "Returns a list of the DROP TABLE SQL statements for the given app."
    275275    from django.db import backend, connection, models, get_introspection_module
     276    from django.db.backends.util import truncate_name
    276277    introspection = get_introspection_module()
    277278
    278279    # This should work even if a connecton isn't available
     
    319320                    col = f.column
    320321                    r_table = model._meta.db_table
    321322                    r_col = model._meta.get_field(f.rel.field_name).column
     323                    r_name = '%s_refs_%s_%s_%s' % (col, r_col, table, r_table)
    322324                    output.append('%s %s %s %s;' % \
    323325                        (style.SQL_KEYWORD('ALTER TABLE'),
    324326                        style.SQL_TABLE(backend.quote_name(table)),
    325327                        style.SQL_KEYWORD(backend.get_drop_foreignkey_sql()),
    326                         style.SQL_FIELD(backend.quote_name('%s_refs_%s_%x' % (col, r_col, abs(hash((table, r_table))))))))
     328                        style.SQL_FIELD(truncate_name(r_name, backend.get_max_name_length()))))
    327329                del references_to_delete[model]
     330            if hasattr(backend, 'get_drop_sequence'):
     331                output.append(backend.get_drop_sequence(model._meta.db_table))
    328332
    329333    # Output DROP TABLE statements for many-to-many tables.
    330334    for model in app_models:
     
    333337            if cursor and table_name_converter(f.m2m_db_table()) in table_names:
    334338                output.append("%s %s;" % (style.SQL_KEYWORD('DROP TABLE'),
    335339                    style.SQL_TABLE(backend.quote_name(f.m2m_db_table()))))
     340                if hasattr(backend, 'get_drop_sequence'):
     341                    output.append(backend.get_drop_sequence("%s_%s"%(model._meta.db_table, f.column)))
    336342
    337343    app_label = app_models[0]._meta.app_label
    338344
  • db/backends/oracle/base.py

    diff -ruN django.branch/db/backends/oracle/base.py django/db/backends/oracle/base.py
    old new  
    144144    raise NotImplementedError
    145145
    146146def get_drop_foreignkey_sql():
    147     return "DROP FOREIGN KEY"
     147    return "DROP CONSTRAINT"
    148148
    149149def get_pk_default_value():
    150150    return "DEFAULT"
     
    168168    END;\n""" % (tr_name, quote_name(table), sq_name)
    169169    return sequence_sql, trigger_sql
    170170
     171def get_drop_sequence(table):
     172    name_length = get_max_name_length() - 3
     173    sq_name = '%s_sq' % util.truncate_name(table, name_length)
     174    drop_sequence_sql = 'DROP SEQUENCE %s;' % sq_name
     175    return drop_sequence_sql
     176
    171177OPERATOR_MAPPING = {
    172178    'exact': '= %s',
    173179    'iexact': "LIKE %s ESCAPE '\\'",
Back to Top