Skip to content
This repository was archived by the owner on Nov 25, 2021. It is now read-only.

Commit 672be4e

Browse files
committed
Refactoring code and supporting new partitioning
1 parent 5f103b2 commit 672be4e

29 files changed

+456
-394
lines changed

README.rst

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,56 @@
1-
django-pg-timepart
2-
==================
1+
django-pg-partitioning
2+
======================
33
.. image:: https://img.shields.io/badge/License-MIT-orange.svg?style=flat-square
4-
:target: https://raw.githubusercontent.com/chaitin/django-pg-timepart/master/LICENSE
4+
:target: https://raw.githubusercontent.com/chaitin/django-pg-partitioning/master/LICENSE
55
.. image:: https://img.shields.io/badge/Django-2.0_2.1-green.svg?style=flat-square&logo=django
66
:target: https://www.djangoproject.com/
77
.. image:: https://img.shields.io/badge/PostgreSQL-11-lightgrey.svg?style=flat-square&logo=postgresql
88
:target: https://www.postgresql.org/
9-
.. image:: https://readthedocs.org/projects/django-pg-timepart/badge/?version=latest&style=flat-square
10-
:target: https://django-pg-timepart.readthedocs.io/en/latest/
11-
.. image:: https://img.shields.io/pypi/v/django-pg-timepart.svg?style=flat-square
12-
:target: https://pypi.org/project/django-pg-timepart/
13-
.. image:: https://api.travis-ci.org/chaitin/django-pg-timepart.svg?branch=master
14-
:target: https://travis-ci.org/chaitin/django-pg-timepart
9+
.. image:: https://readthedocs.org/projects/django-pg-partitioning/badge/?version=latest&style=flat-square
10+
:target: https://django-pg-partitioning.readthedocs.io/en/latest/
11+
.. image:: https://img.shields.io/pypi/v/django-pg-partitioning.svg?style=flat-square
12+
:target: https://pypi.org/project/django-pg-partitioning/
13+
.. image:: https://api.travis-ci.org/chaitin/django-pg-partitioning.svg?branch=master
14+
:target: https://travis-ci.org/chaitin/django-pg-partitioning
1515
.. image:: https://api.codacy.com/project/badge/Grade/c872699c1b254e90b540b053343d1e81
16-
:target: https://www.codacy.com/app/xingji2163/django-pg-timepart?utm_source=github.com&utm_medium=referral&utm_content=chaitin/django-pg-timepart&utm_campaign=Badge_Grade
17-
.. image:: https://codecov.io/gh/chaitin/django-pg-timepart/branch/master/graph/badge.svg
18-
:target: https://codecov.io/gh/chaitin/django-pg-timepart
16+
:target: https://www.codacy.com/app/xingji2163/django-pg-partitioning?utm_source=github.com&utm_medium=referral&utm_content=chaitin/django-pg-partitioning&utm_campaign=Badge_Grade
17+
.. image:: https://codecov.io/gh/chaitin/django-pg-partitioning/branch/master/graph/badge.svg
18+
:target: https://codecov.io/gh/chaitin/django-pg-partitioning
1919

20-
一个实现 PostgreSQL 表基于日期进行分区和管理的 Django 扩展。
21-
它适用于像记录日志、消息或文章等具有时间列的巨型表进行分区管理,定期创建新的分区并归档旧的分区。
20+
一个支持 PostgreSQL 11 原生表分区的 Django 扩展,使您可以在 Django 中创建分区表并管理它们。目前它支持两种分区类型:
21+
22+
- 时间范围分区(Time Range Partitioning):将时序数据分开存储到不同的时间范围分区表中,支持创建连续且不重叠的时间范围分区并进行归档管理。
23+
- 列表分区(List Partitioning):根据分区字段的确定值将数据分开存储到不同的分区表中。
2224

2325
----
2426

25-
A Django extension that implements PostgreSQL tables for partitioning and management based on dates.
26-
It is suitable for partition management of giant tables with time columns like logging, messages or articles,
27-
periodically creating new partitions and archiving old partitions.
27+
A Django extension that supports PostgreSQL 11 native table partitioning, allowing you to create partitioned tables in Django
28+
and manage them. Currently it supports the following two partition types:
29+
30+
- Time Range Partitioning: Separate time series data into different time range partition tables,
31+
support the creation of continuous and non-overlapping time range partitions and archival management.
32+
- List Partitioning: Store data separately into different partition tables based on the determined values of the partition key.
2833

2934
Documentation
30-
https://django-pg-timepart.readthedocs.io/en/latest/
35+
https://django-pg-partitioning.readthedocs.io/en/latest/
3136

3237
TODO
3338
----
34-
* Improve documentation and testing.
39+
- Improve documentation and testing.
40+
- Optimization implementation.
3541

3642
maybe more...
3743

3844
Contributing
3945
------------
40-
4146
If you want to contribute to a project and make it better, you help is very welcome!
42-
Please read through `Contributing Guidelines <https://raw.githubusercontent.com/chaitin/django-pg-timepart/master/CONTRIBUTING.rst>`__.
47+
Please read through `Contributing Guidelines <https://github.com/chaitin/django-pg-partitioning/blob/master/CONTRIBUTING.rst>`__.
4348

4449
License
4550
-------
51+
This project is licensed under the MIT. Please see `LICENSE <https://raw.githubusercontent.com/chaitin/django-pg-partitioning/master/LICENSE>`_.
4652

47-
django-pg-timepart is licensed under the MIT. Please see `LICENSE <https://raw.githubusercontent.com/chaitin/django-pg-timepart/master/LICENSE>`_.
53+
Project Practice
54+
----------------
55+
.. image:: https://raw.githubusercontent.com/chaitin/django-pg-partitioning/master/docs/source/_static/safeline.svg
56+
:target: https://www.chaitin.cn/en/safeline

docs/source/_static/safeline.svg

Lines changed: 44 additions & 0 deletions
Loading

docs/source/api.rst

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
11
API Reference
22
=============
33

4-
.. module:: pg_timepart.manager
4+
.. py:currentmodule:: pg_partitioning.manager
55
6-
.. autoclass:: TimeRangePartitioning
6+
Time Range Partitioning
7+
-----------------------
8+
9+
.. autoclass:: TimeRangePartitioningManager
710
:members:
811

912
.. autoclass:: PartitionConfig
1013
:members: period, interval, attach_tablespace, detach_tablespace, save
1114

1215
.. autoclass:: PartitionLog
13-
:members: is_attached, detach_time, save, delete, truncate, set_tablespace
16+
:members: is_attached, detach_time, save, delete
17+
18+
List Partitioning
19+
-----------------
20+
21+
.. autoclass:: ListRangePartitioningManager
22+
:members:
23+
24+
.. py:currentmodule:: pg_partitioning.shortcuts
25+
26+
Shortcuts
27+
---------
28+
29+
.. automodule:: pg_partitioning.shortcuts
30+
:members: truncate, set_tablespace

docs/source/conf.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
settings.configure(
1414
INSTALLED_APPS=(
15-
"pg_timepart",
15+
"pg_partitioning",
1616
),
1717
)
1818
django.setup()
@@ -31,7 +31,7 @@
3131

3232
master_doc = 'index'
3333

34-
project = 'django-pg-timepart'
34+
project = 'django-pg-partitioning'
3535
copyright = '2019, Chaitin Tech'
3636
author = 'Boyce Li'
3737

@@ -45,7 +45,7 @@
4545

4646
html_theme_options = {
4747
'github_user': 'chaitin',
48-
'github_repo': 'django-pg-timepart',
48+
'github_repo': 'django-pg-partitioning',
4949
'github_type': 'star',
5050
'github_banner': 'true',
5151
'show_powered_by': 'false',
@@ -62,16 +62,16 @@
6262
]
6363
}
6464

65-
htmlhelp_basename = 'django-pg-timepart-doc'
65+
htmlhelp_basename = 'django-pg-partitioning-doc'
6666

6767
man_pages = [
68-
(master_doc, 'django-pg-timepart', 'django-pg-timepart Documentation',
68+
(master_doc, 'django-pg-partitioning', 'django-pg-partitioning Documentation',
6969
[author], 1)
7070
]
7171

7272
texinfo_documents = [
73-
(master_doc, 'django-pg-timepart', 'django-pg-timepart Documentation',
74-
author, 'django-pg-timepart', 'A Django extension that provides database table partition management.',
73+
(master_doc, 'django-pg-partitioning', 'django-pg-partitioning Documentation',
74+
author, 'django-pg-partitioning', 'A Django extension that supports PostgreSQL 11 time ranges and list partitioning.',
7575
'Miscellaneous'),
7676
]
7777

docs/source/decorators.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ If you must use the decorator on a model class that has previously performed a m
66
to back up the model's data, then drop the table, and then import the data after you have created a
77
partitioned table.
88

9-
.. py:currentmodule:: pg_timepart.manager
9+
.. py:currentmodule:: pg_partitioning.manager
1010
11-
.. autodata:: TimeRangePartitioningSupport
11+
.. autodata:: TimeRangePartitioning
12+
:annotation:
13+
14+
.. autodata:: ListPartitioning
1215
:annotation:
1316

1417
Post-Decoration

docs/source/design.rst

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Design
22
======
33

4-
A brief description of the architecture of django-pg-timepart.
4+
A brief description of the architecture of django-pg-partitioning.
55

66
Partitioned Table Support
77
-------------------------
@@ -13,38 +13,29 @@ Some of the operations that Django applies to regular database tables may not be
1313
table, eventually throwing a database exception. Therefore, it is recommended that you read the section on the partition table
1414
in the official database documentation and refer to the relevant implementation inside Django.
1515

16-
Conflict Avoidance
17-
------------------
16+
Constraint Limitations
17+
----------------------
18+
19+
It is important to note that PostgreSQL table partitioning has some restrictions on field constraints.
20+
In order for the extension to work, we turned off Django's automatically generated primary key constraint, but did not do other legality checks.
21+
For example, if you mistakenly used a unique or foreign key constraint, it will throw an exception directly, which is what you are coding and
22+
it needs to be manually circumvented during use.
1823

1924
It is important to note that if the field has the ``primary_key`` or ``unique`` attribute set, but it is not a partitioned field, we will ignore the
2025
``PRIMARY KEY`` or ``UNIQUE`` declarations for that field in the SQL statement generated by Django. Django itself ignores the ``db_index``
2126
attribute of such fields, so you cannot use this method to create field indexes.
2227

23-
A workaround is to add a ``indexes`` declaration in your model, for example
24-
25-
.. code-block:: python
26-
27-
@TimeRangePartitioningSupport("timestamp")
28-
class DataTable(models.Model):
29-
id = models.BigIntegerField(primary_key=True, serialize=False)
30-
timestamp = models.DateTimeField()
31-
data = models.TextField()
32-
33-
class Meta:
34-
# If you do not add this line, id field will not have a index
35-
indexes = (models.Index(fields=("id", )), )
36-
3728
Tablespace
3829
----------
3930

40-
``pg_timepart`` will silently set the tablespace of all local partitioned indexes under one partition to be consistent with
31+
``pg_partitioning`` will silently set the tablespace of all local partitioned indexes under one partition to be consistent with
4132
the partition.
4233

4334
Partition Information
4435
---------------------
4536

46-
``pg_timepart`` saves partition configuration and state information in ``PartitionConfig`` and ``PartitionLog``.
47-
The problem with this is that once this information is inconsistent with the actual situation, ``pg_timepart``
37+
``pg_partitioning`` saves partition configuration and state information in ``PartitionConfig`` and ``PartitionLog``.
38+
The problem with this is that once this information is inconsistent with the actual situation, ``pg_partitioning``
4839
will not work properly, so you can only fix it manually.
4940

5041
Management

docs/source/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
decorators
1010
api
1111
signals
12+
Contributing <https://github.com/chaitin/django-pg-partitioning/blob/master/CONTRIBUTING.rst>
13+
Project License <https://raw.githubusercontent.com/chaitin/django-pg-partitioning/master/LICENSE>

0 commit comments

Comments
 (0)