Skip to content

postgresql_publication: add row filter support#813

Merged
hunleyd merged 1 commit intoansible-collections:mainfrom
gspanos:publication_rowfilter_support
Mar 12, 2025
Merged

postgresql_publication: add row filter support#813
hunleyd merged 1 commit intoansible-collections:mainfrom
gspanos:publication_rowfilter_support

Conversation

@gspanos
Copy link
Collaborator

@gspanos gspanos commented Mar 6, 2025

SUMMARY

Add row filter support to postgresql_publication module, via an extra yaml parameter named rowfilters
This feature is supported since PG Version 15 (search "WHERE" or "row filter"):

Some design decisions:

  1. the parameter allows the user to include or omit the WHERE clause. Internally, if the clause exists we remove it and then add it before constructing the SQL fragment. This simplifies, among other things, the row filter comparison described below.
  2. When it comes to idempotency, and detecting whether the row filter has changed or not, I opted for removing any quoting and whitespace and then compare the strings. The reason for that lies in how PG handles quoting and case sensitivity in general. For example if one writes the row filter condition WHERE ("id" > 10 ), the double quote(") character won't be retained in the pg_publication_tables.rowfilter column. So, short of writing an PG SQL parser, this was the best I could think of.

I have included integration tests for both creation and updating of a publication, and also for testing the "idempotency" handling described above.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

postgresql_publication

ADDITIONAL INFORMATION

This will allow a user to declare a row filter, in conjuction with either tables or columns parameters like so:

  - name: Create publication with specific columns and row filter
    postgresql_publication:
      name: test_pub_rowfilter
      columns:
        mytable1: ['id', 'name']
      rowfilters:
        mytable1: '("id" > 10)'

or in combination with tables parameter

  - name: Create publication with specific columns and row filter
    postgresql_publication:
      name: test_pub_rowfilter
      tables: ['mytable1', 'someothertable2']
      rowfilters:
        mytable1: 'WHERE (id > 10)'

@gspanos gspanos force-pushed the publication_rowfilter_support branch 2 times, most recently from 3f76ea6 to c317ef7 Compare March 6, 2025 14:49
@gspanos gspanos changed the title DRAFT - postgreqsql_publication: add row filter support DRAFT - postgresql_publication: add row filter support Mar 6, 2025
@hunleyd hunleyd marked this pull request as draft March 7, 2025 15:30
Copy link
Collaborator

@Andersson007 Andersson007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gspanos thanks for the PR!
Could you please:

  • Add a changelog fragment, use minor_changes:
  • Add test tasks with check_mode: true to the tests. Also check with pg_query that nothing has actually changed
  • Fix the red tests. If you click details and go to AZP, you'll see what the problems are
  • Also you declare the parameters as mutually exclusive, please declare it in module = AnsibleModule(, there's a similar case already there
  • Also an important question is if you feel committed to fix related bugs if they appear?

@gspanos gspanos force-pushed the publication_rowfilter_support branch from c317ef7 to 92b8bb2 Compare March 11, 2025 12:45
@gspanos gspanos force-pushed the publication_rowfilter_support branch from 92b8bb2 to 9c24fe7 Compare March 11, 2025 14:35
@gspanos gspanos marked this pull request as ready for review March 11, 2025 19:03
@gspanos gspanos changed the title DRAFT - postgresql_publication: add row filter support postgresql_publication: add row filter support Mar 11, 2025
Copy link
Collaborator

@Andersson007 Andersson007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gspanos thanks!

Could other maintainers please take a look?

@hunleyd
Copy link
Collaborator

hunleyd commented Mar 12, 2025

LGTM

@hunleyd hunleyd merged commit 204ad85 into ansible-collections:main Mar 12, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants