Skip to content

Unusable display of alembic_check output #1597

@lachaib

Description

@lachaib

Describe the use case
We're using alembic check in our CI to decorate pull requests with potentially missing DB changes.
The output of alembic check is added as a comment in the pull request, but it's hardly readable.

Example Use

New upgrade operations detected: [('remove_table', Table('some_table', MetaData(), Column('id', UUID(), table=<some_table>, primary_key=True, nullable=False, default=CallableColumnDefault(<function uuid4 at 0x7f18789fafc0>)), Column('url', String(), table=<some_table>, nullable=False), Column('other_table_id', String(), ForeignKey('other_table.id'), table=<some_table>, nullable=False), schema=None)), ('remove_table', Table('another_table', MetaData(), Column('id', UUID(), table=<another_table>, primary_key=True, nullable=False, default=CallableColumnDefault(<function uuid4 at 0x7f187883f4c0>)), Column('url', String(), table=<another_table>, nullable=False), Column('a_column', String(), table=<another_table>), Column('b_column', String(), table=<another_table>), Column('external_id', Integer(), ForeignKey('external_table.id'), table=<another_table>, nullable=False), schema=None))]

What could be output instead, which would summarize it better:

op.remove_table('some_table', if_exists=True)
op.remove_table('another_table', if_exists=True)

or even

DROP TABLE IF EXISTS some_table;
DROP TABLE IF EXISTS another_table;

Additional context

Note that in above expectations I'd be delighted that we can have the if_exists option which is currently added by my rewriter.

What I can propose as solutions:

  • add options as_sql or as_ops to check command, so that we can specify output formats
  • add least rework the AutogenerateDiffsDetected so that I may make a wrapper above the command and catch it to make the display that suits me best. passing diffs/migration_script would be sufficient to change rendering
  • both of the above for people who want to make an even different display format

Have a nice day!

Metadata

Metadata

Assignees

No one assigned

    Labels

    command interfaceuse casenot quite a feature and not quite a bug, something we just didn't think of

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions