Skip to content

Commit

Permalink
fix: πŸ› Add support for MySQL DB in import and export tasks.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrew82 committed May 8, 2024
1 parent eb564ac commit 7418658
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ def db_export(context):
sleep(2) # Wait for the database to be ready

print("Exporting the database as an SQL dump...")
export_cmd = 'exec db sh -c "pg_dump -h localhost -d \${NAUTOBOT_DB_NAME} -U \${NAUTOBOT_DB_USER} > /tmp/nautobot.sql"' # noqa: W605 pylint: disable=anomalous-backslash-in-string
if "docker-compose.mysql.yml" in context.nautobot_docker_compose.compose_files:
export_cmd = 'exec db sh -c "mysqldump -u \${NAUTOBOT_DB_USER} –p \${NAUTOBOT_DB_PASSWORD} \${NAUTOBOT_DB_NAME} nautobot > /tmp/nautobot.sql"' # noqa: W605 pylint: disable=anomalous-backslash-in-string
else:
export_cmd = 'exec db sh -c "pg_dump -h localhost -d \${NAUTOBOT_DB_NAME} -U \${NAUTOBOT_DB_USER} > /tmp/nautobot.sql"' # noqa: W605 pylint: disable=anomalous-backslash-in-string
docker_compose(context, export_cmd, pty=True)

copy_cmd = f"docker cp {context.nautobot_docker_compose.project_name}_postgres_1:/tmp/nautobot.sql dev/nautobot.sql"
Expand All @@ -272,5 +275,8 @@ def db_import(context):
context.run(copy_cmd)

print("Importing DB...\n")
import_cmd = 'exec db sh -c "psql -h localhost -U \${NAUTOBOT_DB_USER} < /tmp/nautobot.sql"' # noqa: W605 pylint: disable=anomalous-backslash-in-string
if "docker-compose.mysql.yml" in context.nautobot_docker_compose.compose_files:
import_cmd = 'exec db sh -c "mysql -u \${NAUTOBOT_DB_USER} –p \${NAUTOBOT_DB_PASSWORD} < /tmp/nautobot.sql"' # noqa: W605 pylint: disable=anomalous-backslash-in-string
else:
import_cmd = 'exec db sh -c "psql -h localhost -U \${NAUTOBOT_DB_USER} < /tmp/nautobot.sql"' # noqa: W605 pylint: disable=anomalous-backslash-in-string
docker_compose(context, import_cmd, pty=True)

0 comments on commit 7418658

Please sign in to comment.