Module reahl.component.migration¶
Support for database schema migration.
Migration¶
-
class
reahl.component.migration.
Migration
(migration_schedule)¶ 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.
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. All the calls scheduled in the same 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. The order in which Migrations are scheduled is carefully crafted based on dependencies between versions.
Added in 2.1.2: Supply custom upgrade logic by calling self.schedule().
-