{"id":22410635,"url":"https://github.com/maxtepkeev/django-db-parti","last_synced_at":"2025-07-31T21:31:05.059Z","repository":{"id":57419700,"uuid":"10402390","full_name":"maxtepkeev/django-db-parti","owner":"maxtepkeev","description":"[DEPRECATED] Django DB Parti - fully automatic database table partitioning for Django","archived":false,"fork":false,"pushed_at":"2014-07-13T17:14:31.000Z","size":372,"stargazers_count":30,"open_issues_count":0,"forks_count":9,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-12-01T21:09:30.171Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxtepkeev.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-05-31T10:03:32.000Z","updated_at":"2024-11-28T16:27:17.000Z","dependencies_parsed_at":"2022-09-03T09:41:17.721Z","dependency_job_id":null,"html_url":"https://github.com/maxtepkeev/django-db-parti","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxtepkeev%2Fdjango-db-parti","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxtepkeev%2Fdjango-db-parti/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxtepkeev%2Fdjango-db-parti/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxtepkeev%2Fdjango-db-parti/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxtepkeev","download_url":"https://codeload.github.com/maxtepkeev/django-db-parti/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228304106,"owners_count":17898920,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-05T13:09:53.359Z","updated_at":"2024-12-05T13:09:54.315Z","avatar_url":"https://github.com/maxtepkeev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"**THIS LIBRARY IS DEPRECATED IN FAVOR OF** `ARCHITECT \u003chttps://github.com/maxtepkeev/architect\u003e`_. **ALL\nFEATURES THAT ARE NOT CURRENTLY BACKPORTED TO ARCHITECT WILL BE BACKPORTED IN THE NEAR TIME. PLEASE\nCONSIDER SWITCHING TO ARCHITECT ASAP, AS DJANGO-DB-PARTI WILL RECEIVE NO FUTURE UPDATES AND BUG FIXES.**\n\nDjango DB Parti\n===============\n\nDjango DB Parti is a package for Django which aim is to make table partitioning on the fly. Partitioning is a\ndivision of one large table into several smaller tables which represent that table. Partitioning is usually\ndone for manageability, performance or availability reasons. If you are unsure whether you need partitioning\nor not, then you almost certainly don't need it.\n\n.. image:: https://badge.fury.io/py/django-db-parti.png\n    :target: http://badge.fury.io/py/django-db-parti\n\n.. image:: https://pypip.in/d/django-db-parti/badge.png\n    :target: https://crate.io/packages/django-db-parti\n\n.. contents:: Table of contents:\n\nFeatures\n--------\n\nDjango DB Parti supports multiple database backends, each database differ from each other in many ways, that\nmeans that some features may be available for one database backend, but not for the other, below you will find\nlist of supported database backends and detailed information which database backend supports which features.\n\nPostgreSQL\n~~~~~~~~~~\n\nImplementation\n++++++++++++++\n\nPostgreSQL's partitioning implementation in Django DB Parti is done purely at the database level. That means\nthat Django DB Parti creates several triggers and functions and inserts them directly into the database, so\neven if you issue direct insert statement from database console and not from Django, everything will work as\nexpected and record will be inserted into the correct partition, if partition doesn't exist, it will be created\nfor you automatically. Also partitions may be created in any order and not only from lower to higher.\n\nPartitioning types\n++++++++++++++++++\n\n* Range partitioning by date/datetime for the following periods:\n\n  - day\n  - week\n  - month\n  - year\n\nLimitations\n+++++++++++\n\n* Currently there are no known limitations for this backend, except that not all partitioning types are supported.\n  New types will be added in next releases of Django DB Parti.\n\nMySQL\n~~~~~\n\nImplementation\n++++++++++++++\n\nMySQL's partitioning implementation in Django DB Parti is done in a mixed way, half at the python level and half\nat the database level. Unfortunately MySQL doesn't support dynamic sql in triggers or functions that are called\nwithin triggers, so the only way to create partitions automatically is to calculate everything at the python\nlevel, then to create needed sql statements based on calculations and issue that statement into the database.\n\nPartitioning types\n++++++++++++++++++\n\n* Range partitioning by date/datetime for the following periods:\n\n  - day\n  - week\n  - month\n  - year\n\nLimitations\n+++++++++++\n\n* Not all partitioning types are supported. New types will be added in next releases of Django DB Parti.\n* Partitioning is not available for bulk inserts (i.e. Django's bulk_create() method) because it doesn't call\n  model's save() method which this backend relies on. Currently there is no known way to remove this limitation.\n* New partitions can be created only from lower to higher, you can overcome this with MySQL's special command\n  REORGANIZE PARTITION which you have to issue from the database console. You can read more about it at the\n  MySQL's documentation. We plan to remove this limitation in one of the future releases of Django DB Parti.\n\nRequirements\n------------\n\n* Django_ \u003e= 1.4.x\n\nInstallation\n------------\n\nFrom pypi_:\n\n.. code-block:: bash\n\n    $ pip install django-db-parti\n\nor clone from github_:\n\n.. code-block:: bash\n\n    $ git clone git://github.com/maxtepkeev/django-db-parti.git\n\nConfiguration\n-------------\n\nAdd dbparti to PYTHONPATH and installed applications:\n\n.. code-block:: python\n\n    INSTALLED_APPS = (\n        ...\n        'dbparti'\n    )\n\nCreate the model as usual which will represent the partitioned table and run syncdb to create a table for the\nmodel, if you are using South for migrations, you can also create the model as usual via migrate. No additional\nsteps required. After that we need to make a few changes to the model:\n\n| 1) In models.py add the following import statement at the top of the file:\n\n.. code-block:: python\n\n    from dbparti.models import Partitionable\n\n| 2) Make your model to inherit from Partitionable, to do that change:\n\n.. code-block:: python\n\n    class YourModelName(models.Model):\n\nto:\n\n.. code-block:: python\n\n    class YourModelName(Partitionable):\n\n| 3) Add a Meta class to your model which inherits from Partitionable.Meta with a few settings (or if you already\n     have a Meta class change it as the following, keep in mind that this is just an example configuration for a\n     model, you have to enter values which represent your exact situation):\n\n.. code-block:: python\n\n    class Meta(Partitionable.Meta):\n        partition_type = 'range'\n        partition_subtype = 'date'\n        partition_range = 'month'\n        partition_column = 'added'\n\n| 4) Lastly we need to initialize some database stuff, to do that execute the following command:\n\n.. code-block:: bash\n\n    $ python manage.py partition app_name\n\nThat's it! Easy right?! Now a few words about what we just did. We made our model to inherit from Partitionable,\nalso we used \"month\" as partition range and \"added\" as partition column, that means that from now on, a new\npartition will be created every month and a value from \"added\" column will be used to determine into what\npartition the data should be saved. Keep in mind that if you add new partitioned models to your apps or change\nany settings in the existing partitioned models, you need to rerun the command from step 4, otherwise the database\nwon't know about your changes. You can also customize how data from that model will be displayed in the Django\nadmin interface, for that you need to do the following:\n\n| 1) In admin.py add the following import statement at the top of the file:\n\n.. code-block:: python\n\n    from dbparti.admin import PartitionableAdmin\n\n| 2) Create admin model as usual and then change:\n\n.. code-block:: python\n\n    class YourAdminModelName(admin.ModelAdmin):\n\nto:\n\n.. code-block:: python\n\n    class YourAdminModelName(PartitionableAdmin):\n\n| 3) Add a setting inside ModelAdmin class which tells how records are displayed in Django admin interface:\n\n.. code-block:: python\n\n    partition_show = 'all'\n\nAvailable settings\n------------------\n\nModel settings\n~~~~~~~~~~~~~~\n\nAll model settings are done inside model's Meta class which should inherit from Partitionable.Meta\n\n``partition_type`` - what partition type will be used on the model, currently accepts the following:\n\n* range\n\n``partition_subtype`` - what partition subtype will be used on the model, currently used only when\n\"partition_type\" is set to \"range\" and accepts the following values:\n\n* date\n\n``partition_range`` - how often a new partition will be created, currently accepts the following:\n\n* day\n* week\n* month\n* year\n\n``partition_column`` - column, which value will be used to determine which partition record belongs to\n\nModelAdmin settings\n~~~~~~~~~~~~~~~~~~~\n\nAll model admin settings are done inside model admin class itself\n\n``partition_show`` - data from which partition will be shown in Django admin, accepts the following values:\n\n* all (default)\n* current\n* previous\n\nExample\n-------\n\nLet's imagine that we would like to create a table for storing log files. Without partitioning our table would\nhave millions of rows very soon and as the table grows performance will become slower. With partitioning we can\ntell database that we want a new table to be created every month and that we will use a value from some column\nto determine to which partition every new record belongs to. To be more specific let's call our table \"logs\", it\nwill have only 3 columns: id, content and added. Now when we insert the following record: id='1', content='blah',\nadded='2013-05-20', this record will be inserted not to our \"logs\" table but to the \"logs_y2013m05\" partition,\nthen if we insert another record like that: id='2', content='yada', added='2013-07-16' it will be inserted to the\npartition \"logs_y2013m07\" BUT the great thing about all of that is that you are doing your inserts/updates/selects\non the table \"logs\"! Again, you are working with the table \"logs\" as usual and you don't may even know that\nactually your data is stored in a lot of different partitions, everything is done for you automatically at the\ndatabase level, isn't that cool ?!\n\nContact and Support\n-------------------\n\nI will be glad to get your feedback, pull requests, issues, whatever. Feel free to contact me for any questions.\n\nCopyright and License\n---------------------\n\n``django-db-parti`` is protected by BSD licence. Check the LICENCE_ for details.\n\n.. _LICENCE: https://github.com/maxtepkeev/django-db-parti/blob/master/LICENSE\n.. _pypi: https://pypi.python.org/pypi/django-db-parti\n.. _github: https://github.com/maxtepkeev/django-db-parti\n.. _Django: https://www.djangoproject.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxtepkeev%2Fdjango-db-parti","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxtepkeev%2Fdjango-db-parti","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxtepkeev%2Fdjango-db-parti/lists"}