Metadata-Version: 2.1
Name: django-postgresql-partitioning
Version: 0.1.1
Summary: Add PostgreSQL table partitioning to Django models
Home-page: https://github.com/starnavi-team/django-postgresql-partitioning
Author: starnavi.io
Author-email: hello@starnavi.io
License: BSD License
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Framework :: Django
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Django <5.1,>=1.11
Requires-Dist: setuptools

# Django partitioning
Django partitioning is a package for Django,
which implement PostgreSQL
[table partitioning](https://www.postgresql.org/docs/10/static/ddl-partitioning.html)
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`...

```bash
$ 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:
```bash
$ 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:
```bash
$ git clone https://github.com/starnavi-team/django-postgresql-partitioning.git
```

Install requirements.

```bash
$ pip install -r requirements.txt
```

Use [tox](http://tox.readthedocs.org/en/latest/) testing tool to run the tests against all supported versions of Python and Django. Install tox globally, and then simply run:

```bash
$ tox
```
