Skip to main content

Clean up your Django database effortlessly with customizable record removal based on your retention policy

Project description


Django Database Purge

The Django Database Purge management command is a tool for efficiently removing unwanted records from your Django project's database based on a specified retention policy. This command helps you keep your database clean and optimized by permanently deleting records that are no longer needed.

Features:

  • Flexible Retention Policy: Define your own retention policy to determine which records should be purged from the database.
  • Efficient Data Management: Easily manage the size of your database by removing outdated or unnecessary records.
  • Customizable: Adapt the command to suit your project's specific requirements and database structure.
  • Safe: Built-in safeguards to prevent accidental data loss, ensuring that only the intended records are purged.

How to Use:

  1. Install django-db-purge by running:
pip install django-db-purge
  1. Include 'dbpurge' in your INSTALLED_APPS settings.

  2. Locate the db_purge.py file in the management/commands directory of the Django dbpurge app.

  3. Add your own values to the retention policies dictionary in the db_purge.py file, based on your requirements. Below is a guide on how to set up the retention policies:

    1. app_name

    • Description: Name of the Django app containing the model.
    • Example: my_django_app

    2. model_name

    • Description: Name of the Django model from which records will be deleted.
    • Example: MyModel

    3. time_based_column_name

    • Description: Name of the column in the model that contains the timestamp or datetime field used for determining the age of records.
    • Example: created_at

    4. data_retention_num_seconds

    • Description: Time duration in seconds for which records will be retained before deletion.
    • Example: 2592000 (for 30 days)

    Example:

    retention_policies = [
        {
            'app_name': 'my_django_app',
            'model_name': 'MyModel',
            'time_based_column_name': 'created_at',
            'data_retention_num_seconds': 2592000,  # 30 days in seconds
        },
        # Add more retention policies as needed
    ]
    
  4. Then, either periodically call the db_purge management command (e.g., via a system cronjob), or install and configure django-cron.

Contributions:

Contributions are welcome! If you encounter any issues or have suggestions for improvements, please submit an issue or pull request on GitHub.

License:

This project is licensed under the MIT License.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_db_purge-0.2.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

django_db_purge-0.2-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file django_db_purge-0.2.tar.gz.

File metadata

  • Download URL: django_db_purge-0.2.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0b3

File hashes

Hashes for django_db_purge-0.2.tar.gz
Algorithm Hash digest
SHA256 bb00b2361eb4549d06000ce5643b151237231d06f13979c518d70fb3d6600d11
MD5 1529eee80649cb4b5f371e2cc35df51a
BLAKE2b-256 2ee92b195f9fa0200e901b4ab8569a39fa861408271e5a6bd469f7adedb5694b

See more details on using hashes here.

File details

Details for the file django_db_purge-0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_db_purge-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 35f9d56ba6136f09b7e82bd226591db5b29d295ee1242987095d37b27d5896c7
MD5 724dbbd4ea14d6beb80a6f6297bdbb42
BLAKE2b-256 de57fcdac196e87b4b7fda191beab571afb30d19776b4fe0f4d516dcbc71ebb4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page