wuttjamaican.db.conf¶
WuttJamaican - database configuration
- wuttjamaican.db.conf.check_alembic_current(config, alembic_config=None)[source]¶
Compare the current revisions in the app database to those found in the migration scripts.
- Parameters:
config – App config object.
alembic_config – Alembic config object, if you have one. Otherwise
make_alembic_config()will be called.
- Returns:
Trueif the DB already has all migrations applied;Falseif not.
- wuttjamaican.db.conf.get_alembic_scriptdir(config, alembic_config=None)[source]¶
Get a “Script Directory” object for Alembic.
This allows for inspection of the migration scripts.
- Parameters:
config – App config object.
alembic_config – Alembic config object, if you have one. Otherwise
make_alembic_config()will be called.
- Returns:
ScriptDirectoryinstance
- wuttjamaican.db.conf.get_engines(config, prefix)[source]¶
Construct and return all database engines defined for a given config prefix.
For instance if you have a config file with:
[wutta.db] keys = default, host default.url = sqlite:///tmp/default.sqlite host.url = sqlite:///tmp/host.sqlite
And then you call this function to get those DB engines:
get_engines(config, 'wutta.db')
The result of that will be like:
{'default': Engine(bind='sqlite:///tmp/default.sqlite'), 'host': Engine(bind='sqlite:///tmp/host.sqlite')}
- Parameters:
config – App config object.
prefix – Prefix for the config “section” which contains DB connection info.
- Returns:
A dictionary of SQLAlchemy engines, with keys matching those found in config.
- wuttjamaican.db.conf.get_setting(session, name)[source]¶
Get a setting value from the DB.
Note that this assumes (for now?) the DB contains a table named
settingwith(name, value)columns.- Parameters:
session – App DB session.
name – Name of the setting to get.
- Returns:
Setting value as string, or
None.
- wuttjamaican.db.conf.make_alembic_config(config)[source]¶
Make and return a new Alembic config object, based on current app config.
This tries to set the following on the Alembic config:
config_file_name- set to app’s primary config filemain option
script_locationmain option
version_locations
The latter 2 are read normally from app config, then set on the Alembic config via
set_main_option().Note
IIUC, Alembic should not need to attempt to read config values from file, as long as we’re able to set the above explicitly. However we set the
config_file_name“just in case” Alembic needs it, but also to ensure it is discoverable from within theenv.pyscript…When a migration script runs, code within
env.pywill callmake_config()using the filename which it inspects from the Alembic config.(Confused yet?!)
- Returns:
alembic.config.Configinstance
- wuttjamaican.db.conf.make_engine_from_config(config_dict, prefix='sqlalchemy.', **kwargs)[source]¶
Construct a new DB engine from configuration dict.
This is a wrapper around upstream
sqlalchemy.engine_from_config(). For even broader context of the SQLAlchemyEngineand their configuration, see Engine Configuration.The purpose of the customization is to allow certain attributes of the engine to be driven by config, whereas the upstream function is more limited in that regard. The following in particular:
poolclasspool_pre_ping
If these options are present in the configuration dict, they will be coerced to appropriate Python equivalents and then passed as kwargs to the upstream function.
An example config file leveraging this feature:
[wutta.db] default.url = sqlite:///tmp/default.sqlite default.poolclass = sqlalchemy.pool:NullPool default.pool_pre_ping = true
Note that if present, the
poolclassvalue must be a “spec” string, as required byload_object().