Commit 24658057 authored by Aymeric Augustin's avatar Aymeric Augustin
Browse files

Fixed #12308 -- Added tablespace support to the PostgreSQL backend.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@16987 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 69e1e618
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -365,6 +365,10 @@ class BaseDatabaseFeatures(object):
    # date_interval_sql can properly handle mixed Date/DateTime fields and timedeltas
    supports_mixed_date_datetime_comparisons = True

    # Does the backend support tablespaces? Default to False because it isn't
    # in the SQL standard.
    supports_tablespaces = False

    # Features that need to be confirmed at runtime
    # Cache whether the confirmation has been performed.
    _confirmed = False
@@ -696,8 +700,12 @@ class BaseDatabaseOperations(object):

    def tablespace_sql(self, tablespace, inline=False):
        """
        Returns the SQL that will be appended to tables or rows to define
        a tablespace. Returns '' if the backend doesn't use tablespaces.
        Returns the SQL that will be used in a query to define the tablespace.

        Returns '' if the backend doesn't support tablespaces.

        If inline is True, the SQL is appended to a row; otherwise it's appended
        to the entire CREATE TABLE or CREATE INDEX statement.
        """
        return ''

+9 −7
Original line number Diff line number Diff line
@@ -57,7 +57,9 @@ class BaseDatabaseCreation(object):
            if tablespace and f.unique:
                # We must specify the index tablespace inline, because we
                # won't be generating a CREATE INDEX statement for this field.
                field_output.append(self.connection.ops.tablespace_sql(tablespace, inline=True))
                tablespace_sql = self.connection.ops.tablespace_sql(tablespace, inline=True)
                if tablespace_sql:
                    field_output.append(tablespace_sql)
            if f.rel:
                ref_output, pending = self.sql_for_inline_foreign_key_references(f, known_models, style)
                if pending:
@@ -74,7 +76,9 @@ class BaseDatabaseCreation(object):
            full_statement.append('    %s%s' % (line, i < len(table_output)-1 and ',' or ''))
        full_statement.append(')')
        if opts.db_tablespace:
            full_statement.append(self.connection.ops.tablespace_sql(opts.db_tablespace))
            tablespace_sql = self.connection.ops.tablespace_sql(opts.db_tablespace)
            if tablespace_sql:
                full_statement.append(tablespace_sql)
        full_statement.append(';')
        final_output.append('\n'.join(full_statement))

@@ -149,11 +153,9 @@ class BaseDatabaseCreation(object):
            qn = self.connection.ops.quote_name
            tablespace = f.db_tablespace or model._meta.db_tablespace
            if tablespace:
                sql = self.connection.ops.tablespace_sql(tablespace)
                if sql:
                    tablespace_sql = ' ' + sql
                else:
                    tablespace_sql = ''
                tablespace_sql = self.connection.ops.tablespace_sql(tablespace)
                if tablespace_sql:
                    tablespace_sql = ' ' + tablespace_sql
            else:
                tablespace_sql = ''
            i_name = '%s_%s' % (model._meta.db_table, self._digest(f.column))
+5 −2
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
    can_defer_constraint_checks = True
    ignores_nulls_in_unique_constraints = False
    has_bulk_insert = True
    supports_tablespaces = True

class DatabaseOperations(BaseDatabaseOperations):
    compiler_module = "django.db.backends.oracle.compiler"
@@ -326,8 +327,10 @@ WHEN (new.%(col_name)s IS NULL)
        return ''

    def tablespace_sql(self, tablespace, inline=False):
        return "%sTABLESPACE %s" % ((inline and "USING INDEX " or ""),
            self.quote_name(tablespace))
        if inline:
            return "USING INDEX TABLESPACE %s" % self.quote_name(tablespace)
        else:
            return "TABLESPACE %s" % self.quote_name(tablespace)

    def value_to_db_datetime(self, value):
        # Oracle doesn't support tz-aware datetimes
+1 −1
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
    has_select_for_update = True
    has_select_for_update_nowait = True
    has_bulk_insert = True

    supports_tablespaces = True

class DatabaseWrapper(BaseDatabaseWrapper):
    vendor = 'postgresql'
+3 −5
Original line number Diff line number Diff line
@@ -44,11 +44,9 @@ class DatabaseCreation(BaseDatabaseCreation):
            db_table = model._meta.db_table
            tablespace = f.db_tablespace or model._meta.db_tablespace
            if tablespace:
                sql = self.connection.ops.tablespace_sql(tablespace)
                if sql:
                    tablespace_sql = ' ' + sql
                else:
                    tablespace_sql = ''
                tablespace_sql = self.connection.ops.tablespace_sql(tablespace)
                if tablespace_sql:
                    tablespace_sql = ' ' + tablespace_sql
            else:
                tablespace_sql = ''

Loading