Commit 5bfa1bb4 authored by Michael Tremer's avatar Michael Tremer

importer: Tolerate that data might exist from other RIRs

Since we are breaking the import into smaller chunks now, it might be
that some data already exists in the database. This is now being
ignored and data won't be replaced.
Signed-off-by: default avatarMichael Tremer <michael.tremer@ipfire.org>
parent e76b8204
......@@ -55,7 +55,8 @@ databasedir = $(localstatedir)/lib/location
pkgconfigdir = $(libdir)/pkgconfig
# Overwrite Python path
pkgpythondir = $(pythondir)/location
#pkgpythondir = $(pythondir)/location
pkgpythondir = /usr/lib/python3/dist-packages/location
%: %.in Makefile
$(SED_PROCESS)
......
......@@ -457,16 +457,59 @@ class CLI(object):
ORDER BY family(network)")
for family in (row.family for row in families):
smallest = self.db.get("SELECT MIN(masklen(network)) AS prefix FROM _rirdata \
WHERE family(network) = %s", family)
# Fetch the smallest mask length in our data set
smallest = self.db.get("""
SELECT
MIN(
masklen(network)
) AS prefix
FROM
_rirdata
WHERE
family(network) = %s""",
family,
)
self.db.execute("INSERT INTO networks(network, country, original_countries, source) \
SELECT network, country, original_countries, source FROM _rirdata \
WHERE masklen(network) = %s AND family(network) = %s", smallest.prefix, family)
# Copy all networks
self.db.execute("""
INSERT INTO
networks
(
network,
country,
original_countries,
source
)
SELECT
network,
country,
original_countries,
source
FROM
_rirdata
WHERE
masklen(network) = %s
AND
family(network) = %s
ON CONFLICT DO
NOTHING""",
smallest.prefix,
family,
)
# ... determine any other prefixes for this network family, ...
prefixes = self.db.query("SELECT DISTINCT masklen(network) AS prefix FROM _rirdata \
WHERE family(network) = %s ORDER BY masklen(network) ASC OFFSET 1", family)
prefixes = self.db.query("""
SELECT
DISTINCT masklen(network) AS prefix
FROM
_rirdata
WHERE
family(network) = %s
ORDER BY
masklen(network) ASC
OFFSET 1""",
family,
)
# ... and insert networks with this prefix in case they provide additional
# information (i. e. subnet of a larger chunk with a different country)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment