sqlalchemy / alembic

A database migrations tool for SQLAlchemy.
MIT License
2.61k stars 234 forks source link

Ignore newlines in expressions for Computed #1393

Closed GeorchW closed 6 months ago

GeorchW commented 6 months ago

Fixes #1391

There's already a function that normalizes expressions from generated columns and server defaults. It looks like this:

def _normalize_computed_default(sqltext: str) -> str:
    """we want to warn if a computed sql expression has changed.  however
    we don't want false positives and the warning is not that critical.
    so filter out most forms of variability from the SQL text.

    """

    return re.sub(r"[ \(\)'\"`\[\]]", "", sqltext).lower()

I added the characters \r\n\t to the ones that are removed.

Description

I added the characters \r\n\t to the regex that normalizes the expressions, that's it. Also added a test case.

Checklist

This pull request is:

Have a nice day!

CaselIT commented 6 months ago

thanks, that change looks good.

I'll add a changelog in gerrit and after review it should be merged. Thanks!

sqla-tester commented 6 months ago

New Gerrit review created for change 69959241d491d9e08c4fb0bc38328a232e89811b: https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5105

sqla-tester commented 6 months ago

Michael Bayer (zzzeek) wrote:

thank you!

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5105

sqla-tester commented 6 months ago

Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5105 has been merged. Congratulations! :)