Skip to content

[BUG] Failing to handle indexes with expressions in #253

@MatthewVallins

Description

@MatthewVallins

Describe the bug**

If a table has an index with an expression in , such as
CREATE INDEX ix_test ON index_test (( CASE WHEN flag THEN value1 ELSE value2 END ));
The code fails to parse it giving the error that it "follows an unexpected structure".

If you use "WithNoConcurrentIndexOps()" it bypasses the failing parsing for the creation of an index, but this does not work if the index already exists and you are trying to create a diff

Expected behaviour**

  1. An index creation with an expression in it should not cause this library to fail
  2. A modification to a database with an expression with an expression in should not cause this library to fail

To Reproduce

Some code to reproduce both occurrences of the issue can be found here: https://github.com/MatthewVallins/pg_schema_diff_idx_failure

Context

I believe the issue is due to regex parsing of the index with the pattern ^(CREATE (UNIQUE )?INDEX )(.*)$"

This doesn't work however for these more complex indexes as it does not capture the new line in them and fails.
Adding (?s) to enable dotall mode (?s)^(CREATE (UNIQUE )?INDEX )(.*)$ should resolve it

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions