directory.migration

Classes

DirectoryMigration

Takes a directory and the structure/configuration it should have in

FieldTypeMigrations

Contains methods to migrate fields from one type to another.

StructuralChanges

Tries to detect structural changes between two formcode blocks.

Module Contents

class directory.migration.DirectoryMigration(directory: onegov.directory.models.Directory, new_structure: str | None = None, new_configuration: DirectoryConfiguration | None = None, old_structure: str | None = None)[source]

Takes a directory and the structure/configuration it should have in the future.

It then migrates the existing directory entries, if possible.

property old_directory_structure: str[source]
property possible: bool[source]
property entries: Iterable[DirectoryEntry][source]
execute() None[source]

To run the migration, run this method. The other methods below should only be used if you know what you are doing.

migrate_directory() None[source]
migrate_entry(entry: onegov.directory.models.directory_entry.DirectoryEntry) None[source]

This function is called after an update to the directory structure. During execution of self.execute(), the directory is migrated. On start of looping trough the entries, an auto_flush occurs, calling the migration observer for the directory, which will instantiate yet another instance of the migration. After this inside execute(), the session is not flusing anymore, and we have to skip, since the values are already migrated and migration will fail when removing fieldsets.

migrate_values(values: dict[str, Any]) None[source]
add_new_fields(values: dict[str, Any]) None[source]
remove_old_fields(values: dict[str, Any]) None[source]
rename_fields(values: dict[str, Any]) None[source]
convert_fields(values: dict[str, Any]) None[source]
class directory.migration.FieldTypeMigrations[source]

Contains methods to migrate fields from one type to another.

possible(old_type: str, new_type: str) bool[source]
get_converter(old_type: str, new_type: str) Callable[[Any], Any] | None[source]
any_to_text(value: Any) str[source]
any_to_textarea(value: Any) str[source]
textarea_to_text(value: str) str[source]
textarea_to_code(value: str) str[source]
text_to_code(value: str) str[source]
date_to_text(value: datetime.date) str[source]
datetime_to_text(value: datetime.datetime) str[source]
time_to_text(value: datetime.time) str[source]
radio_to_checkbox(value: str) list[str][source]
text_to_url(value: str) str[source]
class directory.migration.StructuralChanges(old_structure: str, new_structure: str)[source]

Tries to detect structural changes between two formcode blocks.

Can only be trusted if the detection_successful property is True. If it is not, the detection failed because the changes were too great.

__bool__() bool[source]
detect_removed_fieldsets() None[source]
detect_added_fieldsets() None[source]
detect_added_fields() None[source]
detect_removed_fields() None[source]
do_rename(removed: str, added: str) bool[source]
detect_renamed_fields() None[source]
detect_changed_fields() None[source]