[dataimport] PGHelper should be responsible to retrieve the database schema
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 28 Jan 2016 11:32:12 +0100
changeset 11310 e0b7277e5394
parent 11309 31bf3254be69
child 11311 fd45fc498c1b
[dataimport] PGHelper should be responsible to retrieve the database schema
cubicweb/dataimport/massive_store.py
cubicweb/dataimport/test/test_massive_store.py
--- a/cubicweb/dataimport/massive_store.py	Mon Feb 01 17:31:35 2016 +0100
+++ b/cubicweb/dataimport/massive_store.py	Thu Jan 28 11:32:12 2016 +0100
@@ -117,8 +117,7 @@
 
         self.slave_mode = slave_mode
         self.default_values = get_default_values(cnx.vreg.schema)
-        pg_schema = cnx.repo.config.system_source_config.get('db-namespace') or 'public'
-        self._dbh = PGHelper(self._cnx, pg_schema)
+        self._dbh = PGHelper(cnx)
         self._data_entities = defaultdict(list)
         self._data_relations = defaultdict(list)
         self._now = datetime.now(pytz.utc)
@@ -680,9 +679,10 @@
 
 
 class PGHelper(object):
-    def __init__(self, cnx, pg_schema='public'):
+    def __init__(self, cnx):
         self.cnx = cnx
         # Deals with pg schema, see #3216686
+        pg_schema = cnx.repo.config.system_source_config.get('db-namespace') or 'public'
         self.pg_schema = pg_schema
 
     def application_indexes_constraints(self, tablename):
--- a/cubicweb/dataimport/test/test_massive_store.py	Mon Feb 01 17:31:35 2016 +0100
+++ b/cubicweb/dataimport/test/test_massive_store.py	Thu Jan 28 11:32:12 2016 +0100
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# copyright 2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2013-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr -- mailto:contact@logilab.fr
 #
 # This program is free software: you can redistribute it and/or modify it under
@@ -158,14 +158,11 @@
 
     @staticmethod
     def get_db_descr(cnx):
-        pg_schema = (
-                cnx.repo.config.system_source_config.get('db-namespace')
-                or 'public')
-        pgh = PGHelper(cnx, pg_schema)
+        pgh = PGHelper(cnx)
         all_tables = cnx.system_sql('''
 SELECT table_name
 FROM information_schema.tables
-where table_schema = %(s)s''', {'s': pg_schema}).fetchall()
+where table_schema = %(s)s''', {'s': pgh.pg_schema}).fetchall()
         all_tables_descr = {}
         for tablename, in all_tables:
             all_tables_descr[tablename] = set(pgh.index_list(tablename)).union(