15 # details. |
15 # details. |
16 # |
16 # |
17 # You should have received a copy of the GNU Lesser General Public License along |
17 # You should have received a copy of the GNU Lesser General Public License along |
18 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
19 |
19 |
20 from base64 import b64encode |
|
21 from copy import copy |
|
22 from collections import defaultdict |
20 from collections import defaultdict |
23 from itertools import chain |
21 from itertools import chain |
24 import logging |
22 import logging |
25 from uuid import uuid4 |
23 from uuid import uuid4 |
26 |
24 |
383 cu = self.sql('SELECT 1 from information_schema.tables ' |
381 cu = self.sql('SELECT 1 from information_schema.tables ' |
384 'WHERE table_name=%(t)s AND table_schema=%(s)s', |
382 'WHERE table_name=%(t)s AND table_schema=%(s)s', |
385 {'t': tablename, 's': self.pg_schema}) |
383 {'t': tablename, 's': self.pg_schema}) |
386 return bool(cu.fetchone()) |
384 return bool(cu.fetchone()) |
387 |
385 |
388 def table_indexes_constraints(self, tablename): |
|
389 """Return one dictionary with all indexes by name, another with all constraints by name, |
|
390 for the given table. |
|
391 """ |
|
392 indexes = self.table_indexes(tablename) |
|
393 constraints = self.table_constraints(tablename) |
|
394 _indexes = {} |
|
395 for name, query in indexes.items(): |
|
396 # Remove pkey indexes (automatically created by constraints) |
|
397 # Specific cases of primary key, see #3224079 |
|
398 if name not in constraints: |
|
399 _indexes[name] = query |
|
400 return _indexes, constraints |
|
401 |
|
402 def table_indexes(self, tablename): |
386 def table_indexes(self, tablename): |
403 """Return a dictionary of indexes {index name: index sql}, constraints included.""" |
387 """Return a dictionary of indexes {index name: index sql}, constraints included.""" |
404 indexes = {} |
388 indexes = {} |
405 for name in self._index_names(tablename): |
389 for name in self._index_names(tablename): |
406 indexes[name] = self._index_sql(name) |
390 indexes[name] = self._index_sql(name) |