Skip to content

Commit f851a9a

Browse files
committed
psql_initdb: use JSONB by default
Postgres supports it since version 9, IntelMQ should have defaulted to it since then
1 parent aadc887 commit f851a9a

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Please refer to the [NEWS](NEWS.md) for a list of changes which have an affect o
3939
### Tests
4040

4141
### Tools
42+
- `intelmq.bin.intelmq_psql_initdb`: Use `JSONB` type by default, Postgres supports it since version 9 (PR#2597 by Sebastian Wagner).
4243

4344
### Contrib
4445

intelmq/bin/intelmq_psql_initdb.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2015 Sebastian Wagner, 2023 CERT.at GmbH
1+
# SPDX-FileCopyrightText: 2015-2021 nic.at GmbH, 2022 Sebastian Wagner, 2023 CERT.at GmbH, 2025 Institute for Common Good Technology
22
#
33
# SPDX-License-Identifier: AGPL-3.0-or-later
44

@@ -133,7 +133,7 @@ def _generate_separated_raws_schema(fields: dict, partition_key: str) -> list:
133133

134134
def generate(harmonization_file=HARMONIZATION_CONF_FILE, skip_events=False,
135135
separate_raws=False, partition_key=None, skip_or_replace=False,
136-
use_jsonb=False):
136+
no_jsonb=False):
137137
FIELDS = {}
138138
sql_lines = []
139139

@@ -171,7 +171,7 @@ def generate(harmonization_file=HARMONIZATION_CONF_FILE, skip_events=False,
171171
elif value['type'] == 'UUID':
172172
dbtype = 'UUID'
173173
elif value['type'] in ('JSON', 'JSONDict'):
174-
dbtype = 'jsonb' if use_jsonb else 'json'
174+
dbtype = 'json' if no_jsonb else 'jsonb'
175175
else:
176176
raise ValueError('Unknown type %r.' % value['type'])
177177

@@ -213,8 +213,8 @@ def main():
213213
help="Path to the harmonization file")
214214
parser.add_argument("--skip-or-replace", default=False, action="store_true",
215215
help="Add IF NOT EXISTS or REPLACE directive to created schemas")
216-
parser.add_argument("--jsonb", default=False, action="store_true",
217-
help="Use JSONB type to represent dictionary fields")
216+
parser.add_argument("--no-jsonb", default=True, action="store_true",
217+
help="Do not use JSONB but JSON type to represent dictionary fields")
218218
args = parser.parse_args()
219219

220220
OUTPUTFILE = args.outputfile
@@ -232,7 +232,7 @@ def main():
232232
separate_raws=args.separate_raws,
233233
partition_key=args.partition_key,
234234
skip_or_replace=args.skip_or_replace,
235-
use_jsonb=args.jsonb,
235+
no_jsonb=args.no_jsonb,
236236
)
237237
print("INFO - Writing %s file" % OUTPUTFILE)
238238
fp.write(psql)

intelmq/tests/bin/initdb.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ CREATE TABLE events (
3232
"event_description.text" text,
3333
"event_description.url" text,
3434
"event_hash" varchar(40),
35-
"extra" json,
35+
"extra" jsonb,
3636
"feed.accuracy" real,
3737
"feed.code" varchar(100),
3838
"feed.documentation" text,
@@ -46,7 +46,7 @@ CREATE TABLE events (
4646
"malware.version" text,
4747
"misp.attribute_uuid" varchar(36),
4848
"misp.event_uuid" varchar(36),
49-
"output" json,
49+
"output" jsonb,
5050
"protocol.application" varchar(100),
5151
"protocol.transport" varchar(11),
5252
"raw" text,

intelmq/tests/bin/initdb.sql.license

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
SPDX-FileCopyrightText: 2016 Sebastian Wagner
1+
SPDX-FileCopyrightText: 2016 nic.at GmbH
22
SPDX-License-Identifier: AGPL-3.0-or-later

0 commit comments

Comments
 (0)