Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply_version function after afterEach callback #34

Closed
e11it opened this issue Feb 9, 2023 · 2 comments · Fixed by #39
Closed

Apply_version function after afterEach callback #34

e11it opened this issue Feb 9, 2023 · 2 comments · Fixed by #39

Comments

@e11it
Copy link

e11it commented Feb 9, 2023

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
Copy link
Author

e11it commented Feb 9, 2023

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))

@secwall
Copy link
Collaborator

secwall commented Feb 11, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants