~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to django/db/backends/postgresql/creation.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from django.conf import settings
2
1
from django.db.backends.creation import BaseDatabaseCreation
3
2
 
4
3
class DatabaseCreation(BaseDatabaseCreation):
18
17
        'FilePathField':     'varchar(%(max_length)s)',
19
18
        'FloatField':        'double precision',
20
19
        'IntegerField':      'integer',
 
20
        'BigIntegerField':   'bigint',
21
21
        'IPAddressField':    'inet',
22
22
        'NullBooleanField':  'boolean',
23
23
        'OneToOneField':     'integer',
30
30
    }
31
31
 
32
32
    def sql_table_creation_suffix(self):
33
 
        assert settings.TEST_DATABASE_COLLATION is None, "PostgreSQL does not support collation setting at database creation time."
34
 
        if settings.TEST_DATABASE_CHARSET:
35
 
            return "WITH ENCODING '%s'" % settings.TEST_DATABASE_CHARSET
 
33
        assert self.connection.settings_dict['TEST_COLLATION'] is None, "PostgreSQL does not support collation setting at database creation time."
 
34
        if self.connection.settings_dict['TEST_CHARSET']:
 
35
            return "WITH ENCODING '%s'" % self.connection.settings_dict['TEST_CHARSET']
36
36
        return ''
 
37
 
 
38
    def sql_indexes_for_field(self, model, f, style):
 
39
        if f.db_index and not f.unique:
 
40
            qn = self.connection.ops.quote_name
 
41
            db_table = model._meta.db_table
 
42
            tablespace = f.db_tablespace or model._meta.db_tablespace
 
43
            if tablespace:
 
44
                sql = self.connection.ops.tablespace_sql(tablespace)
 
45
                if sql:
 
46
                    tablespace_sql = ' ' + sql
 
47
                else:
 
48
                    tablespace_sql = ''
 
49
            else:
 
50
                tablespace_sql = ''
 
51
 
 
52
            def get_index_sql(index_name, opclass=''):
 
53
                return (style.SQL_KEYWORD('CREATE INDEX') + ' ' +
 
54
                        style.SQL_TABLE(qn(index_name)) + ' ' +
 
55
                        style.SQL_KEYWORD('ON') + ' ' +
 
56
                        style.SQL_TABLE(qn(db_table)) + ' ' +
 
57
                        "(%s%s)" % (style.SQL_FIELD(qn(f.column)), opclass) +
 
58
                        "%s;" % tablespace_sql)
 
59
 
 
60
            output = [get_index_sql('%s_%s' % (db_table, f.column))]
 
61
 
 
62
            # Fields with database column types of `varchar` and `text` need
 
63
            # a second index that specifies their operator class, which is
 
64
            # needed when performing correct LIKE queries outside the
 
65
            # C locale. See #12234.
 
66
            db_type = f.db_type()
 
67
            if db_type.startswith('varchar'):
 
68
                output.append(get_index_sql('%s_%s_like' % (db_table, f.column),
 
69
                                            ' varchar_pattern_ops'))
 
70
            elif db_type.startswith('text'):
 
71
                output.append(get_index_sql('%s_%s_like' % (db_table, f.column),
 
72
                                            ' text_pattern_ops'))
 
73
        else:
 
74
            output = []
 
75
        return output