Skip to content

Commit

Permalink
Restore using psql due to the stability issues with pg_restore (codes…
Browse files Browse the repository at this point in the history
…tyle) 😫
  • Loading branch information
Sibyx committed Mar 5, 2024
1 parent 105d981 commit 7150605
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions apps/core/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,28 @@ def __init__(self, task: Task, public_only: bool):
def prepare(self):
# Create temporary user
with connection.cursor() as cursor:
cursor.execute(f"CREATE USER {self._database_name} WITH CREATEDB ENCRYPTED PASSWORD '{self._database_password}';")
cursor.execute(
f"CREATE USER {self._database_name} WITH CREATEDB ENCRYPTED PASSWORD '{self._database_password}';"
)
cursor.execute(f"GRANT {self._database_name} TO {settings.DATABASES['default']['USER']};")
cursor.execute(f"CREATE DATABASE {self._database_name} OWNER {self._database_name};")
connection.commit()

# Recover database
command = [
settings.PSQL_PATH,
self._database_name
]
command = [settings.PSQL_PATH, self._database_name]

with open(f"{settings.DBS_DATABASES_PATH}/{self._task.assigment.database}.sql") as f:
proc = subprocess.Popen(" ".join(command), shell=True, stdin=f, stdout=subprocess.DEVNULL, env={
'PGPASSWORD': self._database_password,
'PGUSER': self._database_name,
'PGHOST': settings.DATABASES["default"]["HOST"]
})
proc = subprocess.Popen(
" ".join(command),
shell=True,
stdin=f,
stdout=subprocess.DEVNULL,
env={
"PGPASSWORD": self._database_password,
"PGUSER": self._database_name,
"PGHOST": settings.DATABASES["default"]["HOST"],
},
)
proc.wait()

def run(self):
Expand Down

0 comments on commit 7150605

Please sign in to comment.