Skip to main content

Add PostgreSQL table partitioning to Django models

Project description

Django partitioning

Django partitioning is a package for Django, which implement PostgreSQL table partitioning on the fly, at the database level. It creates several triggers and functions and inserts them directly into the database. After setup partitioning, record will be inserted into the correct partition, if partition doesn't exist, it will be created for you automatically.

Requirements

  • Django >=1.11 <=5.0
  • PostgreSQL >= 8.0

Also, note psycopg2-binary (2.7.5-2.9.9) will be needed as PostgreSQL database adapter.

Installation

Install using pip...

$ pip install django-postgresql-partitioning

Configuration

  • Add partitioning to INSTALLED_APPS:
INSTALLED_APPS = [
    ...
    partitioning,
]
  • Add partitioning configuration to your models:
from partitioning.decorators import partitioning


@partitioning([
    {'type': 'list', 'column': 'tag'},
    {'type': 'range_month', 'column': 'created'},
])
class Message(models.Model):
    text = models.TextField()
    tag = models.CharField(max_length=255)
    created = models.DateTimeField()

  • Lastly setup partitioning:
$ python manage.py setup_partitioning app_name

Available settings

type - partition type, currently supported:

  • list
  • range_day
  • range_week
  • range_month
  • range_year

column - column, used to determine which partition record belongs to.

Testing

Clone the repo:

$ git clone https://github.com/starnavi-team/django-postgresql-partitioning.git

Install requirements.

$ pip install -r requirements.txt

Use tox testing tool to run the tests against all supported versions of Python and Django. Install tox globally, and then simply run:

$ tox

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-postgresql-partitioning-0.1.1.tar.gz (5.5 kB view hashes)

Uploaded Source

Built Distribution

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