Refactor postgresql modules (#291)

* Refactor postgresql_idx to simplify code

Have refactored the postgresql_idx module to:
* Use the class schema in the drop function rather than a passed in one
* Remove the if/else and just return the bool in the drop and create
  functions

* Refactor postgresql_ext module

Have refactored the postgresql_ext module to:
* Remove an unused exception
* Simplify logic in the create and update functions
* Use list comprehension to simplify getting the available version

* Refactor postgresql_user_obj_stat_info module

Have refactored the postgresql_user_obj_stat_info module to:
* Simplify the logic in some of the functions
* Reduce duplicate code

* Add changelog fragment
This commit is contained in:
Thomas O'Donnell 2020-05-12 08:32:06 +02:00 committed by GitHub
parent 2319d928c4
commit 51b8e79203
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 75 deletions

View file

@ -145,6 +145,7 @@ notes:
author:
- Andrew Klychkov (@Andersson007)
- Thomas O'Donnell (@andytom)
extends_documentation_fragment:
- community.general.postgres
@ -418,12 +419,9 @@ class Index(object):
self.executed_query = query
if exec_sql(self, query, return_bool=True, add_to_executed=False):
return True
return exec_sql(self, query, return_bool=True, add_to_executed=False)
return False
def drop(self, schema, cascade=False, concurrent=True):
def drop(self, cascade=False, concurrent=True):
"""Drop PostgreSQL index.
Return True if success, otherwise, return False.
@ -444,20 +442,14 @@ class Index(object):
if concurrent:
query += ' CONCURRENTLY'
if not schema:
query += ' "public"."%s"' % self.name
else:
query += ' "%s"."%s"' % (schema, self.name)
query += ' "%s"."%s"' % (self.schema, self.name)
if cascade:
query += ' CASCADE'
self.executed_query = query
if exec_sql(self, query, return_bool=True, add_to_executed=False):
return True
return False
return exec_sql(self, query, return_bool=True, add_to_executed=False)
# ===========================================
@ -579,7 +571,7 @@ def main():
kw['query'] = index.executed_query
else:
changed = index.drop(schema, cascade, concurrent)
changed = index.drop(cascade, concurrent)
if changed:
kw['state'] = 'absent'