Skip to content

Commit

Permalink
Omit port if it is not defined in Django settings
Browse files Browse the repository at this point in the history
  • Loading branch information
iurisilvio committed Nov 10, 2023
1 parent 5e3ed1e commit 295adee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions django_migrations_ci/backends/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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,
}
Expand Down
7 changes: 5 additions & 2 deletions django_migrations_ci/backends/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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,
}
Expand Down

0 comments on commit 295adee

Please sign in to comment.