Skip to content

Commit

Permalink
Temporary fix for #226.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmafc committed Feb 22, 2022
2 parents 9578608 + 8fd62a8 commit 4c1a12e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
6 changes: 2 additions & 4 deletions pyrseas/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def from_map(self, input_map, langs=None):
input_evttrigs.update({key: input_map[key]})
else:
raise KeyError("Expected typed object, found '%s'" % key)
self.ndb.extensions.from_map(input_extens, langs, self.ndb)
self.ndb.extensions.from_map(input_extens, self.ndb)
self.ndb.languages.from_map(input_langs)
self.ndb.schemas.from_map(input_schemas, self.ndb)
self.ndb.casts.from_map(input_casts, self.ndb)
Expand Down Expand Up @@ -521,9 +521,7 @@ def diff_map(self, input_map, quote_reserved=True):
if quote_reserved:
fetch_reserved_words(self.dbconn)

langs = [lang[0] for lang in self.dbconn.fetchall(
"SELECT name FROM pg_available_extensions() INNER JOIN pg_language ON name = lanname;")]
self.from_map(input_map, langs)
self.from_map(input_map)
if opts.revert:
(self.db, self.ndb) = (self.ndb, self.db)
del self.ndb.schemas['pg_catalog']
Expand Down
14 changes: 11 additions & 3 deletions pyrseas/dbobject/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ def alter(self, inobj, no_owner=True):
"""
return super(Extension, self).alter(inobj, no_owner=no_owner)

KNOWN_LANGS = [
"plpgsql",
"pltcl",
"pltclu",
"plperl",
"plperlu",
"plpythonu",
"plpython2u",
"plpython3u"]

class ExtensionDict(DbObjectDict):
"The collection of extensions in a database"
Expand All @@ -110,11 +119,10 @@ def _from_catalog(self):
self[obj.key()] = obj
self.by_oid[obj.oid] = obj

def from_map(self, inexts, langtempls, newdb):
def from_map(self, inexts, newdb):
"""Initalize the dictionary of extensions by converting the input map
:param inexts: YAML map defining the extensions
:param langtempls: list of language templates
:param newdb: dictionary of input database
"""
for key in inexts:
Expand All @@ -123,7 +131,7 @@ def from_map(self, inexts, langtempls, newdb):
name = key[10:]
inobj = inexts[key]
self[name] = Extension.from_map(name, inobj)
if self[name].name in langtempls:
if self[name].name in KNOWN_LANGS:
lang = {'language %s' % self[name].name: {
'_ext': 'e', 'owner': self[name].owner}}
newdb.languages.from_map(lang)
4 changes: 3 additions & 1 deletion tests/dbobject/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def base_version(self):
return '1.1'
elif self.db.version < 110000:
return '1.3'
return '1.4'
elif self.db.version < 130000:
return '1.4'
return '1.5'

def test_map_extension(self):
"Map an existing extension"
Expand Down
4 changes: 3 additions & 1 deletion tests/dbobject/test_extern_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ def test_map_casts(self):

def test_map_extension(self):
"Map extensions"
TRGM_VERS = '1.4'
TRGM_VERS = '1.5'
if self.db.version < 90300:
TRGM_VERS = '1.0'
elif self.db.version < 90600:
TRGM_VERS = '1.1'
elif self.db.version < 110000:
TRGM_VERS = '1.3'
elif self.db.version < 130000:
TRGM_VERS = '1.4'
self.to_map(["CREATE EXTENSION pg_trgm"], superuser=True,
multiple_files=True)
expmap = {'extension plpgsql': {
Expand Down
2 changes: 2 additions & 0 deletions tests/dbobject/test_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def test_map_language_comment(self):

def test_map_language_bug_103(self):
"Test a function created with language other than plpgsql/plperl"
if self.db.version >= 130000:
self.skipTest('Only available before PG 13')
try:
self.to_map(["CREATE OR REPLACE LANGUAGE plpython3u"])
except psycopg2.OperationalError as e:
Expand Down

0 comments on commit 4c1a12e

Please sign in to comment.