Module reahl.component.migration

Support for database schema migration.

Migration

class reahl.component.migration.Migration(changes)

Represents one logical change that can be made to an existing database schema.

You should extend this class to build your own domain-specific database schema migrations. Set the version class attribute to a string containing the version of your component for which this Migration should be run when upgrading from a previous version.

Never use code imported from your component in a Migration, since Migration code is kept around in future versions of a component and may be run to migrate a schema with different versions of the code in your component.

schedule(phase, to_call, *args, **kwargs)

Call this method to schedule a method call for execution later during the specified migration phase.

Scheduled migrations are first collected from all components, then the calls scheduled for each defined phase are executed. Calls in one phase are executed in the order they were scheduled. Phases are executed in the following order:

‘drop_fk’, ‘drop_pk’, ‘pre_alter’, ‘alter’, ‘create_pk’, ‘indexes’, ‘data’, ‘create_fk’, ‘cleanup’

Parameters:
  • phase – The name of the phase to schedule this call.
  • to_call – The method or function to call.
  • args – The positional arguments to be passed in the call.
  • kwargs – The keyword arguments to be passed in the call.
schedule_upgrades()

Override this method in a subclass in order to supply custom logic for changing the database schema. This method will be called for each of the applicable Migrations listed for all components, in order of dependency of components (the component deepest down in the dependency tree, first).

Added in 2.1.2: Supply custom upgrade logic by calling self.schedule().