from .cfg_app import PpCfgAppError, PpConfigApplication
-__version__ = '0.8.6'
+__version__ = '0.8.7'
LOG = logging.getLogger(__name__)
# =============================================================================
LOG.info("Importing all domainmetadata ...")
src_sql = textwrap.dedent('''\
- SELECT id, domain_id, kind, content
+ SELECT domain_id, kind, content
FROM domainmetadata
WHERE domain_id IN (
SELECT id FROM domains)
+ ORDER BY domain_id, kind, content
''').strip()
if self.verbose > 1:
LOG.debug("Source SQL:\n{}".format(src_sql))
tgt_sql = textwrap.dedent('''\
- INSERT INTO domainmetadata (id, domain_id, kind, content)
- VALUES (%(id)s, %(domain_id)s, %(kind)s, %(content)s)
+ INSERT INTO domainmetadata (domain_id, kind, content)
+ VALUES (%(domain_id)s, %(kind)s, %(content)s)
''').strip()
if self.verbose > 1:
LOG.debug("Target SQL:\n{}".format(tgt_sql))
with self.tgt_connection.cursor() as tgt_cursor:
with self.src_connection.cursor() as src_cursor:
- i = 0
+ nr_total = 0
+ nr_imported = 0
src_cursor.execute(src_sql)
results = src_cursor.fetchall()
return
for result in results:
- i += 1
+ nr_total += 1
+ if result['kind'].lower() == 'also-notify':
+ continue
+ nr_imported += 1
if not self.simulate:
tgt_cursor.execute(tgt_sql, result)
- LOG.info("Imported {} domainmetadata.".format(i))
-
- if self.tgt_db_type != 'mysql':
- LOG.debug("Get max. DomainMetadata Id ...")
- sql = "SELECT MAX(id) AS max_id FROM domainmetadata"
- if self.verbose > 1:
- LOG.debug("SQL: {}".format(sql))
- tgt_cursor.execute(sql)
- result = tgt_cursor.fetchone()
- if self.verbose > 2:
- LOG.debug("Got max domainmetadata Id:\n{}".format(pp(result)))
- max_id = int(result[0])
- sql = "SELECT SETVAL('domainmetadata_id_seq', %s)"
- LOG.debug("Setting curval of domainmetadata_id_seq to {} ...".format(max_id))
- if self.verbose > 1:
- LOG.debug("SQL: {}".format(sql))
- if not self.simulate:
- tgt_cursor.execute(sql, (max_id, ))
+ LOG.info("Imported {i} and rejected {r} domainmetadata.".format(
+ i=nr_imported, r=(nr_total - nr_imported)))
LOG.debug("Commiting changes ...")
self.tgt_connection.commit()