Skip to content
Snippets Groups Projects
Commit a66e24bf authored by Nicolas Dandrimont's avatar Nicolas Dandrimont
Browse files

Ignore psqlrc when loading the rubygems database dump

The SQL dump contains ownership instructions that can't be run if you
don't have the right users in your database clusters. When someone has a
psqlrc with ON_ERROR_STOP, this fails the load of the dump.

Use the opportunity to trigger an exception when psql returns a non-zero
exit code, rather than continue with an empty/inconsistent database.
parent f4aafe02
No related branches found
No related tags found
No related merge requests found
......@@ -119,9 +119,13 @@ class RubyGemsLister(StatelessLister[RubyGemsListerPage]):
dump_tar.extractall(temp_dir)
logger.debug("Populating rubygems database with dump %s", dump_id)
# FIXME: make this work with -v ON_ERROR_STOP=1
psql = subprocess.Popen(
["psql", "-q", db_url],
["psql", "--no-psqlrc", "-q", db_url],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
# passing value of gzip.open as stdin of subprocess.run makes the process
......@@ -133,6 +137,18 @@ class RubyGemsLister(StatelessLister[RubyGemsListerPage]):
psql.stdin.close() # type: ignore
psql.wait()
if psql.returncode != 0:
assert psql.stdout
for line in psql.stdout.readlines():
logger.warning("psql out: %s", line.decode().strip())
assert psql.stderr
for line in psql.stderr.readlines():
logger.warning("psql err: %s", line.decode().strip())
raise ValueError(
"Loading rubygems dump failed with exit code %s.",
psql.returncode,
)
def get_pages(self) -> Iterator[RubyGemsListerPage]:
# spawn a temporary postgres instance (require initdb executable in environment)
with Postgresql() as postgresql:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment