Allow skipping of triggers when dumping MySQL DB

specifically this is b/c of a production demo which makes use of multiple
triggers of the same "type" but my dev maching has older MariaDB which doesn't
allow such multiple triggers
This commit is contained in:
Lance Edgar 2021-02-02 11:31:27 -06:00
parent 9048403130
commit 9ae0015aba

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2020 Lance Edgar
# Copyright © 2010-2021 Lance Edgar
#
# This file is part of Rattail.
#
@ -149,15 +149,17 @@ def script(c, path, database=''):
c.sudo("bash -c 'mysql {} < {}'".format(database, path))
def download_db(c, name, destination=None):
def download_db(c, name, destination=None, **kwargs):
"""
Download a database from the "current" server.
"""
if destination is None:
destination = './{}.sql.gz'.format(name)
triggers = '--skip-triggers' if kwargs.get('skip_triggers') else ''
mysqldump = 'mysqldump {0} --result-file={1}.sql {1}'.format(triggers, name)
# note, we force sudo "as root" to ensure -H flag is used
# (which allows us to leverage /root/.my.cnf config file)
c.sudo('mysqldump --result-file={0}.sql {0}'.format(name), user='root')
c.sudo(mysqldump, user='root')
c.sudo('gzip --force {}.sql'.format(name))
c.get('{}.sql.gz'.format(name), destination)
c.sudo('rm {}.sql.gz'.format(name))