swh.core.cli.db module

swh.core.cli.db.get_sql_for_package(modname)[source]
swh.core.cli.db.populate_database_for_package(modname: str, conninfo: str, flavor: Optional[str] = None) → Tuple[bool, int, Optional[str]][source]

Populate the database, pointed at with conninfo, using the SQL files found in the package modname.

Parameters
  • modname – Name of the module of which we’re loading the files

  • conninfo – connection info string for the SQL database

  • flavor – the module-specific flavor which we want to initialize the database under

Returns

whether the database has been initialized; the current version of the database; if it exists, the flavor of the database.

Return type

Tuple with three elements

swh.core.cli.db.parse_dsn_or_dbname(dsn_or_dbname: str) → Dict[str, str][source]

Parse a psycopg2 dsn, falling back to supporting plain database names as well

swh.core.cli.db.create_database_for_package(modname: str, conninfo: str, template: str = 'template1')[source]

Create the database pointed at with conninfo, and initialize it using -superuser- SQL files found in the package modname.

Parameters
  • modname – Name of the module of which we’re loading the files

  • conninfo – connection info string or plain database name for the SQL database

  • template – the name of the database to connect to and use as template to create the new database

swh.core.cli.db.execute_sqlfiles(sqlfiles: Collection[str], conninfo: str, flavor: Optional[str] = None)[source]

Execute a list of SQL files on the database pointed at with conninfo.

Parameters
  • sqlfiles – List of SQL files to execute

  • conninfo – connection info string for the SQL database

  • flavor – the database flavor to initialize