Skip to content

postgresql_ext - Added idempotence always both in standard and in check mode#545

Merged
hunleyd merged 18 commits intoansible-collections:mainfrom
RealGreenDragon:ext_check_latest_idempotence
Aug 3, 2023
Merged

postgresql_ext - Added idempotence always both in standard and in check mode#545
hunleyd merged 18 commits intoansible-collections:mainfrom
RealGreenDragon:ext_check_latest_idempotence

Conversation

@RealGreenDragon
Copy link
Contributor

@RealGreenDragon RealGreenDragon commented Jul 29, 2023

SUMMARY

I figured out that my PR #504 add idempotence when version=latest in standard mode but NOT in check mode.

It is caused by missing update path check when version=latest but actually the check is possibile.

When latest extension version is requested (both in create and update), the default_version specified in extension control file is installed:

test=# SELECT name, default_version, installed_version FROM pg_catalog.pg_available_extensions WHERE name = 'adminpack';
   name    | default_version | installed_version
-----------+-----------------+-------------------
 adminpack | 2.1             |
(1 row)

test=# CREATE EXTENSION adminpack;
CREATE EXTENSION

test=# SELECT name, default_version, installed_version FROM pg_catalog.pg_available_extensions WHERE name = 'adminpack';
   name    | default_version | installed_version
-----------+-----------------+-------------------
 adminpack | 2.1             | 2.1
(1 row)

test=# DROP EXTENSION adminpack;
DROP EXTENSION

test=# SELECT name, default_version, installed_version FROM pg_catalog.pg_available_extensions WHERE name = 'adminpack';
   name    | default_version | installed_version
-----------+-----------------+-------------------
 adminpack | 2.1             |
(1 row)

test=# CREATE EXTENSION adminpack VERSION '1.0';
CREATE EXTENSION

test=# SELECT name, default_version, installed_version FROM pg_catalog.pg_available_extensions WHERE name = 'adminpack';
   name    | default_version | installed_version
-----------+-----------------+-------------------
 adminpack | 2.1             | 1.0
(1 row)

test=# ALTER EXTENSION adminpack UPDATE;
ALTER EXTENSION

test=# SELECT name, default_version, installed_version FROM pg_catalog.pg_available_extensions WHERE name = 'adminpack';
   name    | default_version | installed_version
-----------+-----------------+-------------------
 adminpack | 2.1             | 2.1
(1 row)

test=# ALTER EXTENSION adminpack UPDATE;
NOTICE:  version "2.1" of extension "adminpack" is already installed
ALTER EXTENSION

test=# SELECT name, default_version, installed_version FROM pg_catalog.pg_available_extensions WHERE name = 'adminpack';
   name    | default_version | installed_version
-----------+-----------------+-------------------
 adminpack | 2.1             | 2.1
(1 row)

It is confirmed also by the source code:

https://github.com/postgres/postgres/blob/d088ba5a5aa410d39b64f013e8433ad9eb3d17f1/src/backend/commands/extension.c#L3056_L3069

My PR add idempotence when provided version=latest also in check mode, parsing the extension default_version and using it to perform all checks (become useless as has been removed).

Other addictions:

  • prev_version and version at module output (possible as default_version is now parsed)
  • queries in output also in check mode
  • error messages in module when it is sure that PostgreSQL command will fail
  • all necessary tests

Bugfixes:

  • module documentation -> queries return value had wrong value in name parameters
  • useless checks in ext_delete function removed
  • fixed ext_create function comment (an argument comment was missing)
  • changelog fragment of my PR postgresql_ext - Added idempotence when version=latest #504 reported the wrong module name
ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

postgresql_ext

ADDITIONAL INFORMATION

The second task of following play results not changed:

- hosts: dbs
  tasks:
    - name: Install extension adminpack at latest version
      community.postgresql.postgresql_ext:
        database: test
        state: present
        name: adminpack
        version: latest

    - name: Update extension adminpack at latest version in check_mode
      community.postgresql.postgresql_ext:
        database: test
        state: present
        name: adminpack
        version: latest
      check_mode: true

@RealGreenDragon RealGreenDragon marked this pull request as ready for review July 29, 2023 15:04
@RealGreenDragon
Copy link
Contributor Author

Ready for review

@RealGreenDragon
Copy link
Contributor Author

@Andersson007 I added new module return values and I put collection version 3.1.0 in documentation. Free to change it if this PR is planned for a different release.

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.

@RealGreenDragon great job is here, thanks!

I took a quick look and left a comment.
I need to schedule a time slot for review. I hope i'll find time in the first half of the week.

Thanks!

@hunleyd
Copy link
Collaborator

hunleyd commented Jul 31, 2023

pinging @keithf4 for his thoughts on the same

@hunleyd hunleyd merged commit a365800 into ansible-collections:main Aug 3, 2023
@hunleyd
Copy link
Collaborator

hunleyd commented Aug 3, 2023

since #504 wasn't backported, i assume this shouldn't be either, @Andersson007 ?

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.

4 participants