2
0
mirror of https://github.com/frappe/frappe_docker.git synced 2024-11-09 23:00:56 +00:00

fix: psql command with subprocess

This commit is contained in:
Revant Nandgaonkar 2020-07-10 15:04:29 +05:30
parent bafa7f6598
commit fa2aff47df

View File

@ -200,15 +200,16 @@ def restore_postgres(config, site_config, database_file):
db_name = site_config.get('db_name') db_name = site_config.get('db_name')
db_password = site_config.get('db_password') db_password = site_config.get('db_password')
psql_command = ["psql", f"postgres://{db_root_user}:{db_root_password}@{db_host}:{db_port}"] psql_command = ["psql"]
psql_uri = f"postgres://{db_root_user}:{db_root_password}@{db_host}:{db_port}"
print('Restoring PostgreSQL') print('Restoring PostgreSQL')
run_command(psql_command + ["-c", f"\"DROP DATABASE IF EXISTS {db_name}\""]) run_command(psql_command + [psql_uri, "-c", f"DROP DATABASE IF EXISTS \"{db_name}\""])
run_command(psql_command + ["-c", f"\"DROP USER IF EXISTS {db_name}\""]) run_command(psql_command + [psql_uri, "-c", f"DROP USER IF EXISTS {db_name}"])
run_command(psql_command + ["-c ", f"\"CREATE DATABASE {db_name}\""]) run_command(psql_command + [psql_uri, "-c", f"CREATE DATABASE \"{db_name}\""])
run_command(psql_command + ["-c", f"\"CREATE user {db_name} password '{db_password}'\""]) run_command(psql_command + [psql_uri, "-c", f"CREATE user {db_name} password '{db_password}'"])
run_command(psql_command + ["-c", f"\"GRANT ALL PRIVILEGES ON DATABASE \"{db_name}\" TO {db_name}\""]) run_command(psql_command + [psql_uri, "-c", f"GRANT ALL PRIVILEGES ON DATABASE \"{db_name}\" TO {db_name}"])
run_command(["psql", f"{psql_command[-1]}/{db_name}", "<", database_file.replace('.gz', '')]) run_command(psql_command + [f"{psql_uri}/{db_name}", "<", database_file.replace('.gz', '')])
def restore_mariadb(config, site_config, database_file): def restore_mariadb(config, site_config, database_file):