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
8 changes: 4 additions & 4 deletions NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```


Expand All @@ -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.
4 changes: 2 additions & 2 deletions sql/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
25 changes: 19 additions & 6 deletions tools/pg_import.py → tools/cq_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

#===============================================================================
Expand Down Expand Up @@ -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')

#===============================================================================
#===============================================================================

Expand Down Expand Up @@ -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))

#===============================================================================

Expand Down