From: Frank Brehm Date: Wed, 17 Jan 2018 10:22:36 +0000 (+0100) Subject: Rejecting all domain metadata of kind 'ALSO-NOTIFY' during import of old PDNS data X-Git-Tag: 0.1.2~22 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=a99b98280c419dfd04c7a015b3e0c91d18bfec10;p=pixelpark%2Fadmin-tools.git Rejecting all domain metadata of kind 'ALSO-NOTIFY' during import of old PDNS data --- diff --git a/pp_lib/import_pdnsdata.py b/pp_lib/import_pdnsdata.py index 5ed65d7..bcb12bb 100644 --- a/pp_lib/import_pdnsdata.py +++ b/pp_lib/import_pdnsdata.py @@ -31,7 +31,7 @@ from .common import pp, to_bool from .cfg_app import PpCfgAppError, PpConfigApplication -__version__ = '0.8.6' +__version__ = '0.8.7' LOG = logging.getLogger(__name__) # ============================================================================= @@ -747,17 +747,18 @@ class ImportPdnsdataApp(PpConfigApplication): 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)) @@ -766,7 +767,8 @@ class ImportPdnsdataApp(PpConfigApplication): 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() @@ -780,27 +782,14 @@ class ImportPdnsdataApp(PpConfigApplication): 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()