Skip to main content

Create JSON indexes concurrently

Project description

Create JSON Indexes concurrently

The functionality provided by this Django App is similar to the indexes, except that it provides an option to create indexes concurrently.

Currently, only Postgres JSON Indexes are supported.

Installation

Install the latest version using pip:

pip install django_indices

Add django_indices to INSTALLED_APPS in the django settings file:

INSTALLED_APPS = (
    ...,
    "django_indices",
)

Run the migrations:

python manage.py migrate django_indices

Add the indices you want to the Meta class of the required Model. Then run the migrate_indices management command to add / remove the indices:

python manage.py migrate_indices

Example

from django.db import models
from django.db.models import Q
from django.contrib.postgres.fields import JSONField

from django_indices import JSONIndex

class Inventory(models.Model):
    data = JSONField()

    class Meta:
        indices = [
            # Creates an index on data->'product_type'
            # Indexes are created concurrently by default, which doesn't lock
            # the table.
            JSONIndex(
                field=["data", "product_type"],
                name="idx_inventory_product_type",
            ),

            # Creates a unique index on data->'product'->>'id'
            #
            # concurrently=False ensures that the index creation will execute
            # in a transaction. So the index is either created successfully,
            # or fails cleanly. This will lock the table though.
            JSONIndex(
                field=["data", "product", "id"],
                name="idx_inventory_product_id",
                unique=True,
                concurrently=False,
            ),

            # Creates a partial compound index on
            # (data->'product'->>'brand', data->'product'->>'size')
            # WHERE data->>'product_type' = 'shoe' OR data->>'product_type' = 'crocs'
            JSONIndex(
                field=(["data", "product", "brand"], ["data", "product", "size"]),
                name="idx_inventory_footwear_brand_size",
                where=(Q(data__product_type="shoe") | Q(data__product_type="crocs"),
            ),

        ]

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-indices-0.0.4.post2.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_indices-0.0.4.post2-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file django-indices-0.0.4.post2.tar.gz.

File metadata

  • Download URL: django-indices-0.0.4.post2.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.0

File hashes

Hashes for django-indices-0.0.4.post2.tar.gz
Algorithm Hash digest
SHA256 2b9b044f8de45c56a768291e85fa5eedb7757d319f16f7da9437da0763f52d16
MD5 1d6c807537b0249148cdcb3aa97371ac
BLAKE2b-256 14a5c46b16138b9856526861bd5fa27f5629256bc073c00913d3eee39c020051

See more details on using hashes here.

File details

Details for the file django_indices-0.0.4.post2-py3-none-any.whl.

File metadata

  • Download URL: django_indices-0.0.4.post2-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.0

File hashes

Hashes for django_indices-0.0.4.post2-py3-none-any.whl
Algorithm Hash digest
SHA256 491a4be89d32699c60b2d4d0f03251caa47b156f932a70a9afe6bf648b48a751
MD5 a06d2c24949602b95533f5e58c211702
BLAKE2b-256 b6684863cda15edb71c402f5723cb385543d8c3f6de85c525b69ebd1db3d5cbf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page