# -*- coding: UTF-8 -*-
# Copyright 2013-2018 by Luc Saffre.
# License: BSD, see file LICENSE for more details.

"""
This defines the :manage:`dump2py` management command.

.. management_command:: dump2py

Write a dump of your database to a set of Python modules.  This dump
is useful for creating a daily backup or before an upgrade with data
migration.

Usage: cd to your project directory and say::

  $ python manage.py dump2py TARGET
  
This will create a python dump of your database to the directory
`TARGET`.

The directory will contain a file :xfile:`restore.py` and a series of
`.py` files (one for every model) which are being :func:`execfile`\ d
from that :xfile:`restore.py`.  

Options:

.. option:: --noinput 

    Do not prompt for user input of any kind.

.. option:: --tolerate

    Tolerate database errors. This can help making a partial snapshot
    of a database which is not (fully) synced with the application
    code.

.. option:: --overwrite

    Don't complain if the TARGET directory already exists. This will
    potentially overwrite existing files.

.. option:: --max-row-count <NUM>

    Change the maximum number of rows per source file from its default
    value (50000) to NUM.

    When a table contains many rows, the resulting :file:`.py` file
    can become so large that it doesn't fit into memory, causing the
    Python process to get killed when it tries to execute it.  To
    avoid this limitation, :xfile:`dump2py` distributes the content
    over several files if a table contains are more than NUM rows.