Page MenuHomeSoftware Heritage

swh db-init should be able to read db cnx creds from a standard swh config file
Closed, MigratedEdits Locked

Description

Currently, the swh db-init command will never read any swh config file to retrieve db access credentials, since this is done using a completely different and mechanism (involving calling pgsql or pg_restore directly from the python code).

It should be possible to execute this command and use standard swh config file to specify db acces credentials.

This would make automatic deployment code (typically docker based environments) much easier to write and improve significantly the ease of use of these bootstrapping commands.

My current proposal is that it should be possible to call this db-init command with only a config file as argument, with some simple business logic making it easy to use. For example, the following config file /path/to/config/yml:

storage:
  cls: local
  args:
    db: postgresql:///?service=swh-storage

objstorage:
  cls: remote
  args:
    url: http://swh-objstorage:5003/

Using this file like:

swh db-init --config-file /path/to/config.yml

or even a better command like (better like more consistent with other swh commands):

swh db -C /path/to/config.yml init

should initialize every local database found in the config file (here only the 'storage' one) using the section name (storage) as swh package name from which sql files to execute are loaded. Here, it would execute sql files from swh.storage to initialize the database for the storage section of this config file.

It should probably be limited to first level sections only, i.e. not attempt to recurse the args to lookup for other local db access declarations.