Code

Ticket #1051: postgresql_schemas_r11651.diff

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

Patche done against rev 11651 (version 1.1.1)

Line 
1Index: django/db/__init__.py
2===================================================================
3--- django/db/__init__.py       (revision 11651)
4+++ django/db/__init__.py       (working copy)
5@@ -50,6 +50,7 @@
6 connection = backend.DatabaseWrapper({
7     'DATABASE_HOST': settings.DATABASE_HOST,
8     'DATABASE_NAME': settings.DATABASE_NAME,
9+    'DATABASE_SCHEMAS': settings.DATABASE_SCHEMAS,
10     'DATABASE_OPTIONS': settings.DATABASE_OPTIONS,
11     'DATABASE_PASSWORD': settings.DATABASE_PASSWORD,
12     'DATABASE_PORT': settings.DATABASE_PORT,
13Index: django/db/backends/postgresql/base.py
14===================================================================
15--- django/db/backends/postgresql/base.py       (revision 11651)
16+++ django/db/backends/postgresql/base.py       (working copy)
17@@ -98,6 +98,7 @@
18 
19     def _cursor(self):
20         set_tz = False
21+        set_path = False
22         settings_dict = self.settings_dict
23         if self.connection is None:
24             set_tz = True
25@@ -113,6 +114,8 @@
26                 conn_string += " host=%s" % settings_dict['DATABASE_HOST']
27             if settings_dict['DATABASE_PORT']:
28                 conn_string += " port=%s" % settings_dict['DATABASE_PORT']
29+            if settings_dict['DATABASE_SCHEMAS']:
30+                set_path = True
31             self.connection = Database.connect(conn_string, **settings_dict['DATABASE_OPTIONS'])
32             self.connection.set_isolation_level(1) # make transactions transparent to all cursors
33             connection_created.send(sender=self.__class__)
34@@ -124,6 +127,8 @@
35             if self._version[0:2] < (8, 0):
36                 # No savepoint support for earlier version of PostgreSQL.
37                 self.features.uses_savepoints = False
38+        if set_path:
39+            cursor.execute("SET search_path TO %s" % ','.join(settings_dict['DATABASE_SCHEMAS']))
40         cursor.execute("SET client_encoding to 'UNICODE'")
41         cursor = UnicodeCursorWrapper(cursor, 'utf-8')
42         return cursor
43Index: django/db/backends/postgresql_psycopg2/base.py
44===================================================================
45--- django/db/backends/postgresql_psycopg2/base.py      (revision 11651)
46+++ django/db/backends/postgresql_psycopg2/base.py      (working copy)
47@@ -75,6 +75,7 @@
48 
49     def _cursor(self):
50         set_tz = False
51+        set_path = False
52         settings_dict = self.settings_dict
53         if self.connection is None:
54             set_tz = True
55@@ -95,6 +96,8 @@
56                 conn_params['host'] = settings_dict['DATABASE_HOST']
57             if settings_dict['DATABASE_PORT']:
58                 conn_params['port'] = settings_dict['DATABASE_PORT']
59+            if settings_dict['DATABASE_SCHEMAS']:
60+                set_path = True
61             self.connection = Database.connect(**conn_params)
62             self.connection.set_client_encoding('UTF8')
63             self.connection.set_isolation_level(self.isolation_level)
64@@ -119,6 +122,8 @@
65                     # versions that support it, but, right now, that's hard to
66                     # do without breaking other things (#10509).
67                     self.features.can_return_id_from_insert = True
68+        if set_path:
69+            cursor.execute("SET search_path TO %s" % ','.join(settings_dict['DATABASE_SCHEMAS']))                       
70         return cursor
71 
72     def _enter_transaction_management(self, managed):
73Index: django/conf/project_template/settings.py
74===================================================================
75--- django/conf/project_template/settings.py    (revision 11651)
76+++ django/conf/project_template/settings.py    (working copy)
77@@ -11,6 +11,7 @@
78 
79 DATABASE_ENGINE = ''           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
80 DATABASE_NAME = ''             # Or path to database file if using sqlite3.
81+DATABASE_SCHEMAS = []          # Databse schemas to be used. Only used in PostgreSQL
82 DATABASE_USER = ''             # Not used with sqlite3.
83 DATABASE_PASSWORD = ''         # Not used with sqlite3.
84 DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
85Index: django/conf/global_settings.py
86===================================================================
87--- django/conf/global_settings.py      (revision 11651)
88+++ django/conf/global_settings.py      (working copy)
89@@ -125,6 +125,7 @@
90 # Database connection info.
91 DATABASE_ENGINE = ''           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
92 DATABASE_NAME = ''             # Or path to database file if using sqlite3.
93+DATABASE_SCHEMAS = []          # Databse schemas to be used. Only used in PostgreSQL
94 DATABASE_USER = ''             # Not used with sqlite3.
95 DATABASE_PASSWORD = ''         # Not used with sqlite3.
96 DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.