diff --git a/README.md b/README.md index bf1346b..45c5fa4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![](https://img.shields.io/pypi/v/alembic-dddl.svg)](https://pypi.org/project/alembic-dddl/) [![](https://img.shields.io/github/v/tag/Vanderhoof/alembic-dddl.svg?label=GitHub)](https://github.com/Vanderhoof/alembic-dddl) ![tests](https://github.com/Vanderhoof/alembic-dddl/actions/workflows/tests.yml/badge.svg) [![codecov](https://codecov.io/gh/Vanderhoof/alembic-dddl/graph/badge.svg?token=BQJBA9PXPN)](https://codecov.io/gh/Vanderhoof/alembic-dddl) -A plugin for [Alembic](https://alembic.sqlalchemy.org/en/latest/) DB migration tool that adds support for arbitrary user-defined objects like views or functions in autogenerate command. +A plugin for [Alembic](https://alembic.sqlalchemy.org/en/latest/) DB migration tool that adds support for arbitrary user-defined objects like views, functions, triggers, etc. in autogenerate command. Alembic DDDL _does not_ compare the objects in the code with their state in the database. Instead, it **only tracks if the source code of the script has changed**, compared to the previous revision. diff --git a/alembic_dddl/src/comparator.py b/alembic_dddl/src/comparator.py index 367f973..d3ed066 100644 --- a/alembic_dddl/src/comparator.py +++ b/alembic_dddl/src/comparator.py @@ -152,7 +152,7 @@ def get_changed_ddls(self) -> List[Tuple[DDL, Optional[RevisionedScript]]]: def _scripts_differ(self, one: str, two: str) -> bool: """ - Compare two scripts, ignoring indentation differences and optinoally ignoring comments. + Compare two scripts, ignoring formatting and optionally ignoring comments. Args: one: the first script source code @@ -161,11 +161,14 @@ def _scripts_differ(self, one: str, two: str) -> bool: Returns: True if the scripts differ, False if the scripts are the same """ - one_norm = sqlparse.format( - one.strip(), reindent_aligned=True, strip_comments=self.ignore_comments - ) - two_norm = sqlparse.format( - two.strip(), reindent_aligned=True, strip_comments=self.ignore_comments - ) + kwargs = { + "reindent_aligned": True, + "strip_comments": self.ignore_comments, + "keyword_case": "upper", + "identifier_case": "lower", + "use_space_around_operators": True, + } + one_norm = sqlparse.format(one.strip(), **kwargs) + two_norm = sqlparse.format(two.strip(), **kwargs) return one_norm != two_norm diff --git a/pyproject.toml b/pyproject.toml index 500355a..0b4929b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "alembic-dddl" -version = "0.1.1" +version = "0.1.2" description = "Alembic extension that adds support for arbitrary user-defined objects like views or functions in autogenerate command." authors = ["Daniil Minukhin "] license = "MIT" diff --git a/tests/src/comprator_test.py b/tests/src/comprator_test.py index 8146721..bd2aa95 100644 --- a/tests/src/comprator_test.py +++ b/tests/src/comprator_test.py @@ -292,6 +292,12 @@ def test_reformatted_script(empty_comparator: CustomDDLComparator) -> None: ) assert empty_comparator._scripts_differ(one=script1, two=script2) is False + @staticmethod + def test_changed_case_script(empty_comparator: CustomDDLComparator) -> None: + script1 = "SELECT * FROM Customers WHERE customer_name LIKE 'John%';" + script2 = "select * fRoM CuStOmErS WHERE CUSTOMER_NAME LIKE 'John%';" + assert empty_comparator._scripts_differ(one=script1, two=script2) is False + @staticmethod def test_comments_ignored(empty_comparator: CustomDDLComparator) -> None: empty_comparator.ignore_comments = True