Skip to content

Commit 199e53b

Browse files
authored
DPE-2764 Add new extensions/plugins (#251)
* Add new extensions/plugins * fix tests
1 parent c672b6e commit 199e53b

File tree

5 files changed

+270
-54
lines changed

5 files changed

+270
-54
lines changed

config.yaml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,98 @@ options:
123123
default: false
124124
type: boolean
125125
description: Enable unaccent extension
126+
plugin_bloom_enable:
127+
default: false
128+
type: boolean
129+
description: Enable bloom extension
130+
plugin_btree_gin_enable:
131+
default: false
132+
type: boolean
133+
description: Enable btree_gin extension
134+
plugin_btree_gist_enable:
135+
default: false
136+
type: boolean
137+
description: Enable btree_gist extension
138+
plugin_cube_enable:
139+
default: false
140+
type: boolean
141+
description: Enable cube extension
142+
plugin_dict_int_enable:
143+
default: false
144+
type: boolean
145+
description: Enable dict_int extension
146+
plugin_dict_xsyn_enable:
147+
default: false
148+
type: boolean
149+
description: Enable dict_xsyn extension
150+
plugin_earthdistance_enable:
151+
default: false
152+
type: boolean
153+
description: Enable earthdistance extension
154+
plugin_fuzzystrmatch_enable:
155+
default: false
156+
type: boolean
157+
description: Enable fuzzystrmatch extension
158+
plugin_intarray_enable:
159+
default: false
160+
type: boolean
161+
description: Enable intarray extension
162+
plugin_isn_enable:
163+
default: false
164+
type: boolean
165+
description: Enable isn extension
166+
plugin_lo_enable:
167+
default: false
168+
type: boolean
169+
description: Enable lo extension
170+
plugin_ltree_enable:
171+
default: false
172+
type: boolean
173+
description: Enable ltree extension
174+
plugin_old_snapshot_enable:
175+
default: false
176+
type: boolean
177+
description: Enable old_snapshot extension
178+
plugin_pg_freespacemap_enable:
179+
default: false
180+
type: boolean
181+
description: Enable pg_freespacemap extension
182+
plugin_pgrowlocks_enable:
183+
default: false
184+
type: boolean
185+
description: Enable pgrowlocks extension
186+
plugin_pgstattuple_enable:
187+
default: false
188+
type: boolean
189+
description: Enable pgstattuple extension
190+
plugin_pg_visibility_enable:
191+
default: false
192+
type: boolean
193+
description: Enable pg_visibility extension
194+
plugin_seg_enable:
195+
default: false
196+
type: boolean
197+
description: Enable seg extension
198+
plugin_tablefunc_enable:
199+
default: false
200+
type: boolean
201+
description: Enable tablefunc extension
202+
plugin_tcn_enable:
203+
default: false
204+
type: boolean
205+
description: Enable tcn extension
206+
plugin_tsm_system_rows_enable:
207+
default: false
208+
type: boolean
209+
description: Enable tsm_system_rows extension
210+
plugin_tsm_system_time_enable:
211+
default: false
212+
type: boolean
213+
description: Enable tsm_system_time extension
214+
plugin_uuid_ossp_enable:
215+
default: false
216+
type: boolean
217+
description: Enable uuid_ossp extension
126218
profile:
127219
description: |
128220
Profile representing the scope of deployment, and used to tune resource allocation.

src/charm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,13 +948,16 @@ def enable_disable_extensions(self, database: str = None) -> None:
948948
database: optional database where to enable/disable the extension.
949949
"""
950950
original_status = self.unit.status
951+
plugins_exception = {"uuid_ossp": '"uuid-ossp"'}
951952
extensions = {}
952953
# collect extensions
953954
for plugin in self.config.plugin_keys():
954955
enable = self.config[plugin]
955956

956957
# Enable or disable the plugin/extension.
957958
extension = "_".join(plugin.split("_")[1:-1])
959+
if extension in plugins_exception:
960+
extension = plugins_exception[extension]
958961
extensions[extension] = enable
959962
self.unit.status = WaitingStatus("Updating extensions")
960963
try:

src/config.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,29 @@ class CharmConfig(BaseConfigModel):
4040
plugin_pg_trgm_enable: bool
4141
plugin_plpython3u_enable: bool
4242
plugin_unaccent_enable: bool
43+
plugin_bloom_enable: bool
44+
plugin_btree_gin_enable: bool
45+
plugin_btree_gist_enable: bool
46+
plugin_cube_enable: bool
47+
plugin_dict_int_enable: bool
48+
plugin_dict_xsyn_enable: bool
49+
plugin_earthdistance_enable: bool
50+
plugin_fuzzystrmatch_enable: bool
51+
plugin_intarray_enable: bool
52+
plugin_isn_enable: bool
53+
plugin_lo_enable: bool
54+
plugin_ltree_enable: bool
55+
plugin_old_snapshot_enable: bool
56+
plugin_pg_freespacemap_enable: bool
57+
plugin_pgrowlocks_enable: bool
58+
plugin_pgstattuple_enable: bool
59+
plugin_pg_visibility_enable: bool
60+
plugin_seg_enable: bool
61+
plugin_tablefunc_enable: bool
62+
plugin_tcn_enable: bool
63+
plugin_tsm_system_rows_enable: bool
64+
plugin_tsm_system_time_enable: bool
65+
plugin_uuid_ossp_enable: bool
4366
request_date_style: Optional[str]
4467
request_standard_conforming_strings: Optional[bool]
4568
request_time_zone: Optional[str]

tests/integration/test_plugins.py

Lines changed: 79 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,35 @@
2424
PG_TRGM_EXTENSION_STATEMENT = "SELECT word_similarity('word', 'two words');"
2525
PLPYTHON3U_EXTENSION_STATEMENT = 'CREATE FUNCTION plpython_test() RETURNS varchar[] AS $$ return "hello" $$ LANGUAGE plpython3u;'
2626
UNACCENT_EXTENSION_STATEMENT = "SELECT ts_lexize('unaccent','Hôtel');"
27+
BLOOM_EXTENSION_STATEMENT = (
28+
"CREATE TABLE tbloom_test (i int);CREATE INDEX btreeidx ON tbloom_test USING bloom (i);"
29+
)
30+
BTREEGIN_EXTENSION_STATEMENT = "CREATE TABLE btree_gin_test (a int4);CREATE INDEX btreeginidx ON btree_gin_test USING GIN (a);"
31+
BTREEGIST_EXTENSION_STATEMENT = "CREATE TABLE btree_gist_test (a int4);CREATE INDEX btreegistidx ON btree_gist_test USING GIST (a);"
32+
CUBE_EXTENSION_STATEMENT = "SELECT cube_inter('(0,-1),(1,1)', '(-2),(2)');"
33+
DICTINT_EXTENSION_STATEMENT = "SELECT ts_lexize('intdict', '12345678');"
34+
DICTXSYN_EXTENSION_STATEMENT = "SELECT ts_lexize('xsyn', 'word');"
35+
EARTHDISTANCE_EXTENSION_STATEMENT = "SELECT earth_distance(ll_to_earth(-81.3927381, 30.2918842),ll_to_earth(-87.6473133, 41.8853881));"
36+
FUZZYSTRMATCH_EXTENSION_STATEMENT = "SELECT soundex('hello world!');"
37+
INTARRAY_EXTENSION_STATEMENT = "CREATE TABLE intarray_test (mid INT PRIMARY KEY, sections INT[]);SELECT intarray_test.mid FROM intarray_test WHERE intarray_test.sections @> '{1,2}';"
38+
ISN_EXTENSION_STATEMENT = "SELECT isbn('978-0-393-04002-9');"
39+
LO_EXTENSION_STATEMENT = "CREATE TABLE lo_test (value lo);"
40+
LTREE_EXTENSION_STATEMENT = "CREATE TABLE ltree_test (path ltree);"
41+
OLD_SNAPSHOT_EXTENSION_STATEMENT = "SELECT * from pg_old_snapshot_time_mapping();"
42+
PG_FREESPACEMAP_EXTENSION_STATEMENT = (
43+
"CREATE TABLE pg_freespacemap_test (i int);SELECT * FROM pg_freespace('pg_freespacemap_test');"
44+
)
45+
PGROWLOCKS_EXTENSION_STATEMENT = (
46+
"CREATE TABLE pgrowlocks_test (i int);SELECT * FROM pgrowlocks('pgrowlocks_test');"
47+
)
48+
PGSTATTUPLE_EXTENSION_STATEMENT = "SELECT * FROM pgstattuple('pg_catalog.pg_proc');"
49+
PG_VISIBILITY_EXTENSION_STATEMENT = "CREATE TABLE pg_visibility_test (i int);SELECT * FROM pg_visibility('pg_visibility_test'::regclass);"
50+
SEG_EXTENSION_STATEMENT = "SELECT '10(+-)1'::seg as seg;"
51+
TABLEFUNC_EXTENSION_STATEMENT = "SELECT * FROM normal_rand(1000, 5, 3);"
52+
TCN_EXTENSION_STATEMENT = "CREATE TABLE tcn_test (i int);CREATE TRIGGER tcn_test_idx AFTER INSERT OR UPDATE OR DELETE ON tcn_test FOR EACH ROW EXECUTE FUNCTION TRIGGERED_CHANGE_NOTIFICATION();"
53+
TSM_SYSTEM_ROWS_EXTENSION_STATEMENT = "CREATE TABLE tsm_system_rows_test (i int);SELECT * FROM tsm_system_rows_test TABLESAMPLE SYSTEM_ROWS(100);"
54+
TSM_SYSTEM_TIME_EXTENSION_STATEMENT = "CREATE TABLE tsm_system_time_test (i int);SELECT * FROM tsm_system_time_test TABLESAMPLE SYSTEM_TIME(1000);"
55+
UUID_OSSP_EXTENSION_STATEMENT = "SELECT uuid_nil();"
2756

2857

2958
@pytest.mark.abort_on_fail
@@ -40,72 +69,72 @@ async def test_plugins(ops_test: OpsTest) -> None:
4069
)
4170
await ops_test.model.wait_for_idle(apps=[DATABASE_APP_NAME], status="active", timeout=1000)
4271

72+
sql_tests = {
73+
"plugin_citext_enable": CITEXT_EXTENSION_STATEMENT,
74+
"plugin_debversion_enable": DEBVERSION_EXTENSION_STATEMENT,
75+
"plugin_hstore_enable": HSTORE_EXTENSION_STATEMENT,
76+
"plugin_pg_trgm_enable": PG_TRGM_EXTENSION_STATEMENT,
77+
"plugin_plpython3u_enable": PLPYTHON3U_EXTENSION_STATEMENT,
78+
"plugin_unaccent_enable": UNACCENT_EXTENSION_STATEMENT,
79+
"plugin_bloom_enable": BLOOM_EXTENSION_STATEMENT,
80+
"plugin_btree_gin_enable": BTREEGIN_EXTENSION_STATEMENT,
81+
"plugin_btree_gist_enable": BTREEGIST_EXTENSION_STATEMENT,
82+
"plugin_cube_enable": CUBE_EXTENSION_STATEMENT,
83+
"plugin_dict_int_enable": DICTINT_EXTENSION_STATEMENT,
84+
"plugin_dict_xsyn_enable": DICTXSYN_EXTENSION_STATEMENT,
85+
"plugin_earthdistance_enable": EARTHDISTANCE_EXTENSION_STATEMENT,
86+
"plugin_fuzzystrmatch_enable": FUZZYSTRMATCH_EXTENSION_STATEMENT,
87+
"plugin_intarray_enable": INTARRAY_EXTENSION_STATEMENT,
88+
"plugin_isn_enable": ISN_EXTENSION_STATEMENT,
89+
"plugin_lo_enable": LO_EXTENSION_STATEMENT,
90+
"plugin_ltree_enable": LTREE_EXTENSION_STATEMENT,
91+
"plugin_old_snapshot_enable": OLD_SNAPSHOT_EXTENSION_STATEMENT,
92+
"plugin_pg_freespacemap_enable": PG_FREESPACEMAP_EXTENSION_STATEMENT,
93+
"plugin_pgrowlocks_enable": PGROWLOCKS_EXTENSION_STATEMENT,
94+
"plugin_pgstattuple_enable": PGSTATTUPLE_EXTENSION_STATEMENT,
95+
"plugin_pg_visibility_enable": PG_VISIBILITY_EXTENSION_STATEMENT,
96+
"plugin_seg_enable": SEG_EXTENSION_STATEMENT,
97+
"plugin_tablefunc_enable": TABLEFUNC_EXTENSION_STATEMENT,
98+
"plugin_tcn_enable": TCN_EXTENSION_STATEMENT,
99+
"plugin_tsm_system_rows_enable": TSM_SYSTEM_ROWS_EXTENSION_STATEMENT,
100+
"plugin_tsm_system_time_enable": TSM_SYSTEM_TIME_EXTENSION_STATEMENT,
101+
"plugin_uuid_ossp_enable": UUID_OSSP_EXTENSION_STATEMENT,
102+
}
103+
104+
def enable_disable_config(enabled: False):
105+
config = {}
106+
for plugin in sql_tests.keys():
107+
config[plugin] = f"{enabled}"
108+
return config
109+
43110
# Check that the available plugins are disabled.
44111
primary = await get_primary(ops_test, f"{DATABASE_APP_NAME}/0")
45112
password = await get_password(ops_test, primary)
46113
address = get_unit_address(ops_test, primary)
114+
115+
config = enable_disable_config(False)
116+
await ops_test.model.applications[DATABASE_APP_NAME].set_config(config)
117+
await ops_test.model.wait_for_idle(apps=[DATABASE_APP_NAME], status="active")
118+
47119
logger.info("checking that the plugins are disabled")
48120
with db_connect(host=address, password=password) as connection:
49121
connection.autocommit = True
50-
51-
# Test citext extension disabled.
52-
with pytest.raises(psycopg2.Error):
53-
connection.cursor().execute(CITEXT_EXTENSION_STATEMENT)
54-
55-
# Test debversion extension disabled.
56-
with pytest.raises(psycopg2.Error):
57-
connection.cursor().execute(DEBVERSION_EXTENSION_STATEMENT)
58-
59-
# Test hstore extension disabled.
60-
with pytest.raises(psycopg2.Error):
61-
connection.cursor().execute(HSTORE_EXTENSION_STATEMENT)
62-
63-
# Test pg_trgm extension disabled.
64-
with pytest.raises(psycopg2.Error):
65-
connection.cursor().execute(PG_TRGM_EXTENSION_STATEMENT)
66-
67-
# Test PL/Python extension disabled.
68-
with pytest.raises(psycopg2.Error):
69-
connection.cursor().execute(PLPYTHON3U_EXTENSION_STATEMENT)
70-
71-
# Test unaccent extension disabled.
72-
with pytest.raises(psycopg2.Error):
73-
connection.cursor().execute(UNACCENT_EXTENSION_STATEMENT)
122+
for query in sql_tests.values():
123+
with pytest.raises(psycopg2.Error):
124+
connection.cursor().execute(query)
74125
connection.close()
75126

76127
# Enable the plugins.
77128
logger.info("enabling the plugins")
78-
config = {
79-
"plugin_citext_enable": "True",
80-
"plugin_debversion_enable": "True",
81-
"plugin_hstore_enable": "True",
82-
"plugin_pg_trgm_enable": "True",
83-
"plugin_plpython3u_enable": "True",
84-
"plugin_unaccent_enable": "True",
85-
}
129+
130+
config = enable_disable_config(True)
86131
await ops_test.model.applications[DATABASE_APP_NAME].set_config(config)
87132
await ops_test.model.wait_for_idle(apps=[DATABASE_APP_NAME], status="active")
88133

89134
# Check that the available plugins are enabled.
90135
logger.info("checking that the plugins are enabled")
91136
with db_connect(host=address, password=password) as connection:
92137
connection.autocommit = True
93-
94-
# Test citext extension enabled.
95-
connection.cursor().execute(CITEXT_EXTENSION_STATEMENT)
96-
97-
# Test debversion extension enabled.
98-
connection.cursor().execute(DEBVERSION_EXTENSION_STATEMENT)
99-
100-
# Test hstore extension enabled.
101-
connection.cursor().execute(HSTORE_EXTENSION_STATEMENT)
102-
103-
# Test pg_trgm extension enabled.
104-
connection.cursor().execute(PG_TRGM_EXTENSION_STATEMENT)
105-
106-
# Test PL/Python extension enabled.
107-
connection.cursor().execute(PLPYTHON3U_EXTENSION_STATEMENT)
108-
109-
# Test unaccent extension enabled.
110-
connection.cursor().execute(UNACCENT_EXTENSION_STATEMENT)
138+
for query in sql_tests.values():
139+
connection.cursor().execute(query)
111140
connection.close()

tests/unit/test_charm.py

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,81 @@ def test_enable_disable_extensions(self, _):
321321
plugin_unaccent_enable:
322322
default: false
323323
type: boolean
324-
profile:
325-
default: production
326-
type: string
327324
plugin_debversion_enable:
328325
default: false
329-
type: boolean"""
326+
type: boolean
327+
plugin_bloom_enable:
328+
default: false
329+
type: boolean
330+
plugin_btree_gin_enable:
331+
default: false
332+
type: boolean
333+
plugin_btree_gist_enable:
334+
default: false
335+
type: boolean
336+
plugin_cube_enable:
337+
default: false
338+
type: boolean
339+
plugin_dict_int_enable:
340+
default: false
341+
type: boolean
342+
plugin_dict_xsyn_enable:
343+
default: false
344+
type: boolean
345+
plugin_earthdistance_enable:
346+
default: false
347+
type: boolean
348+
plugin_fuzzystrmatch_enable:
349+
default: false
350+
type: boolean
351+
plugin_intarray_enable:
352+
default: false
353+
type: boolean
354+
plugin_isn_enable:
355+
default: false
356+
type: boolean
357+
plugin_lo_enable:
358+
default: false
359+
type: boolean
360+
plugin_ltree_enable:
361+
default: false
362+
type: boolean
363+
plugin_old_snapshot_enable:
364+
default: false
365+
type: boolean
366+
plugin_pg_freespacemap_enable:
367+
default: false
368+
type: boolean
369+
plugin_pgrowlocks_enable:
370+
default: false
371+
type: boolean
372+
plugin_pgstattuple_enable:
373+
default: false
374+
type: boolean
375+
plugin_pg_visibility_enable:
376+
default: false
377+
type: boolean
378+
plugin_seg_enable:
379+
default: false
380+
type: boolean
381+
plugin_tablefunc_enable:
382+
default: false
383+
type: boolean
384+
plugin_tcn_enable:
385+
default: false
386+
type: boolean
387+
plugin_tsm_system_rows_enable:
388+
default: false
389+
type: boolean
390+
plugin_tsm_system_time_enable:
391+
default: false
392+
type: boolean
393+
plugin_uuid_ossp_enable:
394+
default: false
395+
type: boolean
396+
profile:
397+
default: production
398+
type: string"""
330399
harness = Harness(PostgresqlOperatorCharm, config=config)
331400
self.addCleanup(harness.cleanup)
332401
harness.begin()

0 commit comments

Comments
 (0)