Ticket #1051: postgresql_schemas_r11651.diff

File postgresql_schemas_r11651.diff, 4.7 KB (added by asux, 5 years ago)

Patche done against rev 11651 (version 1.1.1)

  • django/db/__init__.py

     
    5050connection = backend.DatabaseWrapper({
    5151    'DATABASE_HOST': settings.DATABASE_HOST,
    5252    'DATABASE_NAME': settings.DATABASE_NAME,
     53    'DATABASE_SCHEMAS': settings.DATABASE_SCHEMAS,
    5354    'DATABASE_OPTIONS': settings.DATABASE_OPTIONS,
    5455    'DATABASE_PASSWORD': settings.DATABASE_PASSWORD,
    5556    'DATABASE_PORT': settings.DATABASE_PORT,
  • django/db/backends/postgresql/base.py

     
    9898
    9999    def _cursor(self):
    100100        set_tz = False
     101        set_path = False
    101102        settings_dict = self.settings_dict
    102103        if self.connection is None:
    103104            set_tz = True
     
    113114                conn_string += " host=%s" % settings_dict['DATABASE_HOST']
    114115            if settings_dict['DATABASE_PORT']:
    115116                conn_string += " port=%s" % settings_dict['DATABASE_PORT']
     117            if settings_dict['DATABASE_SCHEMAS']:
     118                set_path = True
    116119            self.connection = Database.connect(conn_string, **settings_dict['DATABASE_OPTIONS'])
    117120            self.connection.set_isolation_level(1) # make transactions transparent to all cursors
    118121            connection_created.send(sender=self.__class__)
     
    124127            if self._version[0:2] < (8, 0):
    125128                # No savepoint support for earlier version of PostgreSQL.
    126129                self.features.uses_savepoints = False
     130        if set_path:
     131            cursor.execute("SET search_path TO %s" % ','.join(settings_dict['DATABASE_SCHEMAS']))
    127132        cursor.execute("SET client_encoding to 'UNICODE'")
    128133        cursor = UnicodeCursorWrapper(cursor, 'utf-8')
    129134        return cursor
  • django/db/backends/postgresql_psycopg2/base.py

     
    7575
    7676    def _cursor(self):
    7777        set_tz = False
     78        set_path = False
    7879        settings_dict = self.settings_dict
    7980        if self.connection is None:
    8081            set_tz = True
     
    9596                conn_params['host'] = settings_dict['DATABASE_HOST']
    9697            if settings_dict['DATABASE_PORT']:
    9798                conn_params['port'] = settings_dict['DATABASE_PORT']
     99            if settings_dict['DATABASE_SCHEMAS']:
     100                set_path = True
    98101            self.connection = Database.connect(**conn_params)
    99102            self.connection.set_client_encoding('UTF8')
    100103            self.connection.set_isolation_level(self.isolation_level)
     
    119122                    # versions that support it, but, right now, that's hard to
    120123                    # do without breaking other things (#10509).
    121124                    self.features.can_return_id_from_insert = True
     125        if set_path:
     126            cursor.execute("SET search_path TO %s" % ','.join(settings_dict['DATABASE_SCHEMAS']))                       
    122127        return cursor
    123128
    124129    def _enter_transaction_management(self, managed):
  • django/conf/project_template/settings.py

     
    1111
    1212DATABASE_ENGINE = ''           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
    1313DATABASE_NAME = ''             # Or path to database file if using sqlite3.
     14DATABASE_SCHEMAS = []          # Databse schemas to be used. Only used in PostgreSQL
    1415DATABASE_USER = ''             # Not used with sqlite3.
    1516DATABASE_PASSWORD = ''         # Not used with sqlite3.
    1617DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
  • django/conf/global_settings.py

     
    125125# Database connection info.
    126126DATABASE_ENGINE = ''           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
    127127DATABASE_NAME = ''             # Or path to database file if using sqlite3.
     128DATABASE_SCHEMAS = []          # Databse schemas to be used. Only used in PostgreSQL
    128129DATABASE_USER = ''             # Not used with sqlite3.
    129130DATABASE_PASSWORD = ''         # Not used with sqlite3.
    130131DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
Back to Top