rattail.db Module

rattail.db - Database helper module

Functions

rattail.db.class_dependency_sorter(key=None)

Function generator which returns a sort algorithm used to reorder objects according to their class (really, table) dependencies. key should be a callable which expects an object and yields the object’s class. If key is not given then all objects are assumed to be classes themselves.

rattail.db.clear_default_engine()

Clears the default database engine. Also resets an internal variable so that the next time the default engine is requested it will attempt to create the engine anew from current config.

rattail.db.core_schema_is_installed(engine=None)

Returns boolean indicating whether or not the core schema is installed to the database represented by engine.

rattail.db.get_database_uuid(engine=None)

Returns the unique identifier for a database.

rattail.db.get_database_version(engine=None, extension=None)

Returns the SQLAlchemy-Migrate version found in the database represented by engine. If extension is provided, the version for its schema is returned; otherwise the core’s schema is assumed.

rattail.db.get_engine_from_config(config)

Returns a sqlalchemy.engine.Engine instance, consructed from the values found in config. config is expected to be an instance of ConfigParser.RawConfigParser, and the relevant values are expected to be defined in config‘s DEFAULT section, with sqlalchemy. as the prefix. (sqlalchemy.engine_from_config() is used to create the engine.)

rattail.db.install_core_schema(engine=None, version=None)

Installs the core schema to the database represented by engine.

A version may be provided, although this is probably only useful for tests.

rattail.db.subscribe_to(remote_engine, class_names, local_engine=None, subscriber_name=None)

Establishes a (one-way) data subscription between two databases. Once this subscription has been created, the remote database will begin to advertise changes it makes to the relevant classes, which the local database can then pull.

remote_engine and local_engine (if provided) should be sqlalchemy.Engine instances. The default engine will be used as local if none is provided.

class_names should be either a single string or a list of strings.

subscriber_name, if provided, will become the Subscriber.name used to represent the local database’s subscription to the remote, within the remote database. The local database uuid will be used if no name is provided.

rattail.db.upgrade_schema(extension=None, engine=None, version=None)

Upgrades a schema within the database represented by engine. If extension is provided, then its schema will be upgraded; otherwise the core is assumed.

A version may be provided, although this is probably only useful for tests.

Table Of Contents

Previous topic

rattail.console Module

Next topic

rattail.enum Module

This Page