Fork me on GitHub

sqlalchemy_imageattach.migration — Storage migration

class sqlalchemy_imageattach.migration.MigrationPlan(function)

Iterable object that yields migrated images.

execute(callback=None)

Execute the plan. If optional callback is present, it is invoked with an Image instance for every migrated image.

Parameters:callback (Callable) – an optional callback that takes an Image instance. it’s called zero or more times
sqlalchemy_imageattach.migration.migrate(session, declarative_base, source, destination)

Migrate all image data from source storage to destination storage. All data in source storage are not deleted.

It does not execute migration by itself alone. You need to execute() the plan it returns:

migrate(session, Base, source, destination).execute()

Or iterate it using for statement:

for i in migrate(session, Base, source, destination):
    # i is an image just done migration
    print(i)
Parameters:
Returns:

iterable migration plan which is not executed yet

Return type:

MigrationPlan

sqlalchemy_imageattach.migration.migrate_class(session, cls, source, destination)

Migrate all image data of cls from source storage to destination storage. All data in source storage are not deleted.

It does not execute migration by itself alone. You need to execute() the plan it returns:

migrate_class(session, UserPicture, source, destination).execute()

Or iterate it using for statement:

for i in migrate_class(session, UserPicture, source, destination):
    # i is an image just done migration
    print(i)
Parameters:
  • session (sqlalchemy.orm.session.Session) – SQLAlchemy session
  • cls (sqlalchemy.ext.declarative.api.DeclarativeMeta) – declarative mapper class
  • source (Store) – the storage to copy image data from
  • destination (Store) – the storage to copy image data to
Returns:

iterable migration plan which is not executed yet

Return type:

MigrationPlan