https://github.com/starnavi-team/django-postgresql-partitioning
https://github.com/starnavi-team/django-postgresql-partitioning
django django-orm postgres postgresql python3
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/starnavi-team/django-postgresql-partitioning
- Owner: starnavi-team
- License: isc
- Created: 2018-09-24T11:10:26.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-05-21T14:00:31.000Z (9 months ago)
- Last Synced: 2025-09-27T18:02:39.281Z (5 months ago)
- Topics: django, django-orm, postgres, postgresql, python3
- Language: Python
- Homepage:
- Size: 38.1 KB
- Stars: 12
- Watchers: 4
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```