Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion intelmq/bin/intelmq_psql_initdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
4 changes: 2 additions & 2 deletions intelmq/tests/bin/initdb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
19 changes: 19 additions & 0 deletions intelmq/tests/bin/test_psql_initdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down