From 295adeeb9fa0e7f74b7ced53678494841d682ada Mon Sep 17 00:00:00 2001 From: Iuri de Silvio Date: Fri, 10 Nov 2023 23:37:23 +0100 Subject: [PATCH] Omit port if it is not defined in Django settings --- django_migrations_ci/backends/mysql.py | 7 +++++-- django_migrations_ci/backends/postgresql.py | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/django_migrations_ci/backends/mysql.py b/django_migrations_ci/backends/mysql.py index 6939603..dc1d1c3 100644 --- a/django_migrations_ci/backends/mysql.py +++ b/django_migrations_ci/backends/mysql.py @@ -5,7 +5,10 @@ def dump(connection, output_file): ctx, env = _ctx(connection.settings_dict) - mysqldump = "mysqldump -h {host} -P {port} -u {user} --result-file {output_file} {database}" # noqa: E501 + if ctx["port"]: + mysqldump = "mysqldump -h {host} -P {port} -u {user} --result-file {output_file} {database}" # noqa: E501 + else: + mysqldump = "mysqldump -h {host} -u {user} --result-file {output_file} {database}" # noqa: E501 shell.exec(mysqldump.format(output_file=output_file, **ctx), env) @@ -27,7 +30,7 @@ def _ctx(db_conf): data = { "host": db_conf["HOST"], - "port": db_conf["PORT"] or 3306, + "port": db_conf["PORT"], "user": db_conf["USER"], "database": database, } diff --git a/django_migrations_ci/backends/postgresql.py b/django_migrations_ci/backends/postgresql.py index 3d1c070..5925559 100644 --- a/django_migrations_ci/backends/postgresql.py +++ b/django_migrations_ci/backends/postgresql.py @@ -3,7 +3,10 @@ def dump(connection, output_file): ctx, env = _ctx(connection.settings_dict) - pg_dump = "pg_dump --no-owner --inserts -h {host} -p {port} -U {user} -f {output_file} {database}" # noqa: E501 + if ctx["port"]: + pg_dump = "pg_dump --no-owner --inserts -h {host} -p {port} -U {user} -f {output_file} {database}" # noqa: E501 + else: + pg_dump = "pg_dump --no-owner --inserts -h {host} -U {user} -f {output_file} {database}" # noqa: E501 shell.exec(pg_dump.format(output_file=output_file, **ctx), env) @@ -21,7 +24,7 @@ def _ctx(db_conf): data = { "host": db_conf["HOST"], - "port": db_conf["PORT"] or 5432, + "port": db_conf["PORT"], "user": db_conf["USER"], "database": database, }