From 00226aa7e263bdf1147299a727a52432c64cff9d Mon Sep 17 00:00:00 2001 From: Haitao Zheng <203365637+0xTaoZ@users.noreply.github.com> Date: Fri, 3 Jul 2026 02:09:51 +0200 Subject: [PATCH] Use bigint for PostgreSQL ASN fields --- intelmq/bin/intelmq_psql_initdb.py | 4 +++- intelmq/tests/bin/initdb.sql | 4 ++-- intelmq/tests/bin/test_psql_initdb.py | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/intelmq/bin/intelmq_psql_initdb.py b/intelmq/bin/intelmq_psql_initdb.py index 82359bdb7..e39e59ad2 100644 --- a/intelmq/bin/intelmq_psql_initdb.py +++ b/intelmq/bin/intelmq_psql_initdb.py @@ -177,8 +177,10 @@ def generate(harmonization_file=HARMONIZATION_CONF_FILE, skip_events=False, dbtype = 'timestamp with time zone' elif value['type'] == 'Boolean': dbtype = 'boolean' - elif value['type'] in ('Integer', 'ASN'): + elif value['type'] == 'Integer': dbtype = 'integer' + elif value['type'] == 'ASN': + dbtype = 'bigint' elif value['type'] in ('Float', 'Accuracy'): dbtype = 'real' elif value['type'] == 'UUID': diff --git a/intelmq/tests/bin/initdb.sql b/intelmq/tests/bin/initdb.sql index 3d3b4a2fc..21c2ca6fb 100644 --- a/intelmq/tests/bin/initdb.sql +++ b/intelmq/tests/bin/initdb.sql @@ -17,7 +17,7 @@ CREATE TABLE events ( "destination.account" text, "destination.allocated" timestamp with time zone, "destination.as_name" text, - "destination.asn" integer, + "destination.asn" bigint, "destination.domain_suffix" text, "destination.fqdn" text, "destination.geolocation.cc" varchar(2), @@ -71,7 +71,7 @@ CREATE TABLE events ( "source.account" text, "source.allocated" timestamp with time zone, "source.as_name" text, - "source.asn" integer, + "source.asn" bigint, "source.domain_suffix" text, "source.fqdn" text, "source.geolocation.cc" varchar(2), diff --git a/intelmq/tests/bin/test_psql_initdb.py b/intelmq/tests/bin/test_psql_initdb.py index bedb0ce6f..559cfe1f3 100644 --- a/intelmq/tests/bin/test_psql_initdb.py +++ b/intelmq/tests/bin/test_psql_initdb.py @@ -64,6 +64,25 @@ def test_skip_generating_events_table_schema(self): self.assertNotIn("CREATE TABLE events", generated) self.assertNotIn("CREATE INDEX", generated) + def test_asn_fields_use_bigint(self): + simple_harmonization = { + "event": { + "source.asn": { + "type": "ASN" + }, + "source.port": { + "type": "Integer" + } + } + } + with open(self.harmonization_path, "w+") as f: + json.dump(simple_harmonization, f) + + generated = psql_initdb.generate(self.harmonization_path) + + self.assertIn('"source.asn" bigint', generated) + self.assertIn('"source.port" integer', generated) + def test_separated_raws_view_schema(self): expected_view = """ CREATE VIEW public.v_events AS