Skip to content

When using alembic revision --autogenerate is it possible to preview the automatically generated file without saving it? #1286

Answered by zzzeek
ghost asked this question in Usage Questions
Discussion options

You must be logged in to vote

this is not built in and would not be that simple because we have things like post write hooks that look for a file.

so the best we could do here would be a recipe that extends on the existing recipe for dont generate empty migrations which adds a render step inside of the custom hook. we have a utility function for this which is render_python_code

this is not tested but it makes use of the x argument to add alembic revision --autogenerate -x print:

def run_migrations_online():

    # ...

    def process_revision_directives(context, revision, directives):
        if config.cmd_opts.autogenerate and config.cmd_opts.x == 'print':
            script = directives[0]
            print(render_…

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
2 replies
@CaselIT
Comment options

@ghost
Comment options

Comment options

You must be logged in to vote
5 replies
@zzzeek
Comment options

@ghost
Comment options

@zzzeek
Comment options

@CaselIT
Comment options

@ghost
Comment options

Answer selected
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants