yandex/pgmigrate

Apply_version function after afterEach callback

e11it opened this issue · 2 comments

e11it commented

Hi!

We use set role and reset role statements in beforeEach callback and afterEach callback accordingly.

For example we run pgmigrate with user A and do set role B in the beforeEach callback.
Function _init_schema executed with user A but _apply_version executed with user B because afterEach callback is not called.

_apply_version(version, base_dir, user, schema, cursor)

if callbacks.afterEach:

Is it possible to change order of functions and do callbacks.afterEach before _apply_version?

e11it commented

To be clear. I understand that _apply_version do two things: apply version|migration and save information about migration.

Here is changes that I propose to do:

558             version_info = _apply_version(version, base_dir, user, schema, cursor)
559
560             if callbacks.afterEach:
561                 LOG.info('Executing afterEach callbacks:')
562                 for callback in callbacks.afterEach:
563                     LOG.info(callback)
564                     _apply_file(callback, cursor)
565
566             cursor.execute(
567                SQL('INSERT INTO {schema}.schema_version '
568                    '(version, description, installed_by) '
569                    'VALUES (%s::bigint, %s, %s)').format(schema=Identifier(schema)),
570                (text(version), version_info.meta['description'], user))

Hello. This use case seems reasonable. I'll try to add an option to reorder the execution of callbacks and the update of migration info. This way we will not break backwards compatibility.