This instance will be upgraded to Heptapod 0.26.0rc1 on 2021-10-25 at 14:00 UTC+2 (a few minutes of down time)

Commit a2915490 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Heptapod: new generic method to run SQL statements

It is called `psql` for emphasis that it is not based on
a library client but on the CLI (ran in the proper context).

For now, not implemented for source and remote instances, but
we could do it by reading proper connection information from
GitLab config for the former and from command-line args for
the latter (of course a remote port can well not be available
at all).

Could also be less hardcoded in the future if needed.
parent 69af850f342d
......@@ -463,6 +463,15 @@ class Heptapod:
"""Call GitLab Rake"""
raise NotImplementedError('rake')
def psql(self, statement):
"""Calls psql on the instance database.
This is *not* an access through the client library, we cannot separate
arguments as is usually mandatory in regular applications to prevent
SQL injections.
raise NotImplementedError('psql')
def remove_all_backups(self):
"""Remove all existing backups with no impediment for new backups.
......@@ -712,6 +721,13 @@ class OmnibusHeptapod(Heptapod):
for service in services:
self.run_shell(base_cmd + (service, ))
def psql(self, statement):
# db name is hardcoded.
# This is good enough for now, but we could
# read it from config if needed.
return self.run_shell(('gitlab-psql', 'gitlabhq_production',
'-c', statement))
class DockerHeptapod(OmnibusHeptapod):
......@@ -779,12 +795,9 @@ class DockerHeptapod(OmnibusHeptapod):
Sometimes GitLab fails to clean Project routes after failed tests.
logger.warn("Cleaning up leftover route at %r", route_path)
'gitlab-psql', 'gitlabhq_production',
'-c', "DELETE FROM routes "
"WHERE source_type='%s' "
" AND path='%s'" % (source_type, route_path)
self.psql("DELETE FROM routes "
"WHERE source_type='%s' "
" AND path='%s'" % (source_type, route_path))
class SourceHeptapod(Heptapod):
......@@ -893,3 +906,13 @@ class GdkHeptapod(SourceHeptapod):
for service in services:
def psql(self, statement):
# Assuming Unix socket, and db name is hardcoded.
# This is good enough for now, but we could
# read connection parameters from gdk.yml if needed.
return self.run_shell(('psql',
'-h', os.path.join(self.gdk_root, 'postgresql'),
'-c', statement,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment