From e60a7025a05ad7db0509cf4d6f67f0d13ab69eae Mon Sep 17 00:00:00 2001 From: napakalas Date: Wed, 11 Mar 2026 15:23:37 +1300 Subject: [PATCH 1/4] CQ: Use COMPETENCY_ env vars and add DB confirmation before import (#74). --- tools/pg_import.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tools/pg_import.py b/tools/pg_import.py index 34a4703..c5c693d 100644 --- a/tools/pg_import.py +++ b/tools/pg_import.py @@ -34,16 +34,16 @@ #=============================================================================== -PG_DATABASE = 'map-knowledge' +COMPETENCY_DATABASE = os.environ.get('COMPETENCY_DATABASE', 'map-knowledge') -KNOWLEDGE_USER = os.environ.get('KNOWLEDGE_USER') -KNOWLEDGE_HOST = os.environ.get('KNOWLEDGE_HOST', 'localhost:5432') +COMPETENCY_USER = os.environ.get('COMPETENCY_USER') +COMPETENCY_HOST = os.environ.get('COMPETENCY_HOST', 'localhost:5432') #=============================================================================== -def pg_import(knowledge: KnowledgeList): +def cq_import(knowledge: KnowledgeList): #======================================= - competency_db = CompetencyDatabase(KNOWLEDGE_USER, KNOWLEDGE_HOST, PG_DATABASE) + competency_db = CompetencyDatabase(COMPETENCY_USER, COMPETENCY_HOST, COMPETENCY_DATABASE) competency_db.import_knowledge(knowledge, True) #=============================================================================== @@ -77,6 +77,13 @@ def store_knowledge(args) -> KnowledgeList: store.close() return knowledge + +def confirm_import(database_name: str) -> bool: +#============================================= + print(f'About to import knowledge into database: {database_name}') + response = input('Proceed with import? [y/N]: ').strip().lower() + return response in ('y', 'yes') + #=============================================================================== #=============================================================================== @@ -106,7 +113,13 @@ def main(): logging.basicConfig(level=logging.DEBUG) elif not args.quiet: logging.basicConfig(level=logging.INFO) - pg_import(args.func(args)) + + logging.info('Database: %s', COMPETENCY_DATABASE) + if not confirm_import(COMPETENCY_DATABASE): + logging.warning('Import cancelled by user.') + return + + cq_import(args.func(args)) #=============================================================================== From 79b8eb1ed9722d466db533537f9a899bd8bdefe9 Mon Sep 17 00:00:00 2001 From: napakalas Date: Wed, 11 Mar 2026 15:25:22 +1300 Subject: [PATCH 2/4] CQ: Rename pg_import.py to cq_import.py (#74). --- tools/{pg_import.py => cq_import.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tools/{pg_import.py => cq_import.py} (100%) diff --git a/tools/pg_import.py b/tools/cq_import.py similarity index 100% rename from tools/pg_import.py rename to tools/cq_import.py From 10e529bd4a3713ed9ddd35191e579b104c1c5e85 Mon Sep 17 00:00:00 2001 From: napakalas Date: Thu, 12 Mar 2026 13:19:46 +1300 Subject: [PATCH 3/4] CQ: Fix and update CQ setup instructions (#74). --- sql/setup.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/setup.md b/sql/setup.md index 23058cf..8efb305 100644 --- a/sql/setup.md +++ b/sql/setup.md @@ -18,7 +18,7 @@ $ psql -d "map-knowledge" -f sql/map-knowledge.schema.sql -U abi $ poetry install --with tools $ poetry shell -$ export KNOWLEDGE_USER=abi:XXX +$ export COMPETENCY_USER=abi:XXX $ python tools/cq_upgrade.py -$ python tools/pg_import.py json sckan/sckan-2026-02-11.json +$ python tools/cq_import.py json sckan/sckan-2026-02-11.json ``` From ccb552f99c780384524f1ccd09c84415e7aaa66d Mon Sep 17 00:00:00 2001 From: napakalas Date: Fri, 13 Mar 2026 10:05:48 +1300 Subject: [PATCH 4/4] CQ: Update NOTES.md to use the new command name (#74). --- NOTES.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/NOTES.md b/NOTES.md index 7a196d6..f957d39 100644 --- a/NOTES.md +++ b/NOTES.md @@ -5,15 +5,15 @@ This will save SCKAN as JSON, formatted for `map-knowldege`. ```sh -$ python tools/sckan_connectivity.py --store-directory sckan load --sckan sckan-2024-09-21 --save +$ python tools/sckan_connectivity.py --store-directory sckan load --sckan sckan-2026-02-11 --save ``` ## Reloading CQ database with SCKAN NPO knowledge ```sh $ source .venv/bin/activate -$ export KNOWLEDGE_USER=xxxxxx:xxxxxxx -$ PYTHONPATH=. python tools/pg_import.py json sckan/sckan-2024-09-21.json +$ export COMPETENCY_USER=xxxxxx:xxxxxxx +$ PYTHONPATH=. python tools/cq_import.py json sckan/sckan-2026-02-11.json ``` @@ -28,4 +28,4 @@ $ PYTHONPATH=. python tools/pg_import.py json sckan/sckan-2024-09-21.json 7. Update flatmap manifests to use the new SCKAN and rebuild the maps (automatic, on push (tag??)). 8. Map knowledge in the staging CQ database will be automatically updated when a map is rebuilt. 9. At promotion time, update production databases (`mapknowledge.db` and production CQ database). -10. At promotion time, copy rebuilt maps from staging to production -- map knowledge in the production CQ database will be automatically updated. +10. At promotion time, copy rebuilt maps from staging to production -- map knowledge in the production CQ database will be automatically updated.