Metadata-Version: 2.4
Name: djanquiltdb-plugin-postgres-denormalize
Version: 1.1.0
Summary: Repair helpers for django-postgres-denormalize copies in DjanQuiltDB projects
Author-email: DjanQuiltDB Project <djanquiltdb@portal42.net>
License-Expression: BSD-3-Clause
Project-URL: Homepage, https://github.com/DjanQuiltDB/djanquiltdb
Project-URL: Documentation, https://djanquiltdb.readthedocs.io/en/latest/plugins/postgres-denormalize/index.html
Project-URL: Source, https://github.com/DjanQuiltDB/djanquiltdb/tree/master/packages/djanquiltdb-plugin-postgres-denormalize
Project-URL: Issues, https://github.com/DjanQuiltDB/djanquiltdb/issues
Project-URL: Changelog, https://github.com/DjanQuiltDB/djanquiltdb/blob/master/packages/djanquiltdb-plugin-postgres-denormalize/CHANGELOG.rst
Keywords: django,database,sharding,postgresql,denormalization,triggers
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Framework :: Django
Classifier: Framework :: Django :: 6.0
Classifier: Framework :: Django :: 6.1
Classifier: Topic :: Database
Requires-Python: >=3.12
Description-Content-Type: text/x-rst
License-File: LICENSE
Requires-Dist: django<7.0,>=6.0
Requires-Dist: djanquiltdb<5.0,>=4.3
Requires-Dist: django-postgres-denormalize<2.0,>=1.1
Provides-Extra: lint
Requires-Dist: ruff==0.15.21; extra == "lint"
Provides-Extra: test
Requires-Dist: coverage; extra == "test"
Requires-Dist: psycopg[binary]>=3.0.0; extra == "test"
Requires-Dist: dj-database-url; extra == "test"
Provides-Extra: docs
Requires-Dist: sphinx<10,>=8; extra == "docs"
Provides-Extra: dev
Requires-Dist: djanquiltdb-plugin-postgres-denormalize[docs,lint,test]; extra == "dev"
Requires-Dist: pre-commit; extra == "dev"
Requires-Dist: tox>=4.21; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

.. The logo needs an absolute URL: this README is the PyPI long description, where a relative path renders broken.

.. image:: https://raw.githubusercontent.com/DjanQuiltDB/djanquiltdb/master/assets/icon-128.png
    :alt: DjanQuiltDB
    :width: 128

=======================================
djanquiltdb-plugin-postgres-denormalize
=======================================

.. image:: https://img.shields.io/pypi/v/djanquiltdb-plugin-postgres-denormalize.svg
    :target: https://pypi.org/project/djanquiltdb-plugin-postgres-denormalize/
    :alt: PyPI

.. image:: https://img.shields.io/pypi/pyversions/djanquiltdb-plugin-postgres-denormalize.svg
    :target: https://pypi.org/project/djanquiltdb-plugin-postgres-denormalize/
    :alt: Supported Python versions

.. image:: https://img.shields.io/pypi/frameworkversions/django/djanquiltdb-plugin-postgres-denormalize.svg
    :target: https://pypi.org/project/djanquiltdb-plugin-postgres-denormalize/
    :alt: Supported Django versions

.. image:: https://img.shields.io/badge/postgres-17%20%7C%2018-4169e1?logo=postgresql&logoColor=white
    :target: https://www.postgresql.org/
    :alt: Supported PostgreSQL versions

.. image:: https://github.com/DjanQuiltDB/djanquiltdb/actions/workflows/ci.yml/badge.svg
    :target: https://github.com/DjanQuiltDB/djanquiltdb/actions/workflows/ci.yml
    :alt: CI

.. image:: https://img.shields.io/readthedocs/djanquiltdb/latest
    :target: https://djanquiltdb.readthedocs.io/en/latest/plugins/postgres-denormalize/index.html
    :alt: Documentation

.. image:: https://img.shields.io/codecov/c/github/DjanQuiltDB/djanquiltdb/master?flag=postgres-denormalize
    :target: https://app.codecov.io/gh/DjanQuiltDB/djanquiltdb
    :alt: Coverage

.. image:: https://img.shields.io/pypi/l/djanquiltdb-plugin-postgres-denormalize.svg
    :target: https://github.com/DjanQuiltDB/djanquiltdb/blob/master/LICENSE
    :alt: BSD-3-Clause licence

`django-postgres-denormalize <https://django-postgres-denormalize.readthedocs.io/>`_ stores copies of related columns
in ordinary columns, and keeps them up to date with Postgres triggers. `DjanQuiltDB
<https://github.com/djanquiltdb/djanquiltdb>`_ shards a database across schemas and nodes. This library finds and
corrects the copies that are out of date, in one shard or in every shard::

    from djanquiltdb.utils.postgres_denormalize import repair_every_shard, stale_rows

    stale_rows(shard)  # {<class 'Task'>: 3}
    repair_every_shard()

Install it through DjanQuiltDB's extra::

    pip install djanquiltdb[postgres-denormalize]

The `installation guide
<https://djanquiltdb.readthedocs.io/en/latest/plugins/postgres-denormalize/installation.html>`_ describes each step in
full. ``postgres_denormalize`` and the ``pgtrigger`` app that it builds on go in ``INSTALLED_APPS``. Run every node that
stores copies at SERIALIZABLE, because at a lower level a copy can differ from its lookup path, and retry the
transactions that fail with a serialization error::

    # settings.py
    from django.db.backends.postgresql.psycopg_any import IsolationLevel

    INSTALLED_APPS = [
        ...
        'djanquiltdb',
        'pgtrigger',
        'postgres_denormalize',
        ...
    ]

    DATABASES = {
        'default': {
            ...,
            'OPTIONS': {'isolation_level': IsolationLevel.SERIALIZABLE},
        },
    }

Do not copy a column of a mirrored or public model. The triggers of such a copy only reach the current shard, and fail
outside one.

Full documentation is at https://djanquiltdb.readthedocs.io/en/latest/plugins/postgres-denormalize/index.html.

Development
===========

This package is developed in the `DjanQuiltDB repository <https://github.com/DjanQuiltDB/djanquiltdb>`_ beside
``djanquiltdb`` itself. Tests run through tox against the Postgres containers in the repository's
``docker-compose.yml``; see ``DOCKER.md`` at the repository root::

    docker compose run --rm test tox

Requirements
------------

* Python 3.12 to 3.15
* Django 6.0 or 6.1
* PostgreSQL 17 or 18
* djanquiltdb 4.3.0 or newer 4.x
* django-postgres-denormalize 1.1.0 or newer 1.x

Unlike DjanQuiltDB and its other plugins, this plugin does not support Django 5.2. django-postgres-denormalize relies
on Django returning the columns that a trigger computes from an UPDATE's RETURNING clause, so that a saved instance has
their new values, and Django 6.0 is the first release that does.
