upgrade-zulip: Support arbitrary database user and dbname.

Co-authored-by: Adam Birds <adam.birds@adbwebdesigns.co.uk>
This commit is contained in:
Alex Vandiver 2021-05-24 20:44:38 -07:00 committed by Tim Abbott
parent 1d59330cbc
commit 7ff3c9f966
2 changed files with 5 additions and 2 deletions

View File

@ -139,6 +139,7 @@ if os.path.exists("/etc/init.d/postgresql"):
if glob.glob("/usr/share/postgresql/*/extension/tsearch_extras.control"): if glob.glob("/usr/share/postgresql/*/extension/tsearch_extras.control"):
# Remove legacy tsearch_extras package references # Remove legacy tsearch_extras package references
run_psql_as_postgres( run_psql_as_postgres(
config_file=config_file,
sql_query="DROP EXTENSION IF EXISTS tsearch_extras;", sql_query="DROP EXTENSION IF EXISTS tsearch_extras;",
) )
subprocess.check_call(["apt-get", "remove", "-y", "postgresql-*-tsearch-extras"]) subprocess.check_call(["apt-get", "remove", "-y", "postgresql-*-tsearch-extras"])

View File

@ -581,8 +581,10 @@ def get_deploy_options(config_file: configparser.RawConfigParser) -> List[str]:
def run_psql_as_postgres( def run_psql_as_postgres(
config_file: configparser.RawConfigParser,
sql_query: str, sql_query: str,
) -> None: ) -> None:
dbname = get_config(config_file, "postgresql", "database_name", "zulip")
subcmd = " ".join( subcmd = " ".join(
map( map(
shlex.quote, shlex.quote,
@ -590,8 +592,8 @@ def run_psql_as_postgres(
"psql", "psql",
"-v", "-v",
"ON_ERROR_STOP=1", "ON_ERROR_STOP=1",
# TODO: Stop hardcoding the database name. "-d",
"zulip", dbname,
"-c", "-c",
sql_query, sql_query,
], ],