Skip to content

Multi-database support #9

@copelco

Description

@copelco

Projects using multiple databases cannot use django-pgviews outside of the default database.

I'm using django-pgviews on a project connected to two databases. In our case, the default database is quite small, while the 2nd database is large and could make valuable use of materialized views.

To support multiple databases, I think the following modifications need to be made:

  1. Modify how connection cursors are obtained to make use of the connections dictionary:

    https://github.com/mikicz/django-pgviews/blob/269c17f3e08c76a7cb971afcf2241ee76858589c/django_pgviews/view.py#L176

    https://github.com/mikicz/django-pgviews/blob/269c17f3e08c76a7cb971afcf2241ee76858589c/django_pgviews/view.py#L441

  2. Update view creation to refer to the database router's allow_migrate so views are only created within the appropriate database.

  3. Update management commands to support running against specific databases, as migrate works. For example:

    python manage.py sync_pgviews  # default db
    python manage.py sync_pgviews --database=customers

In the end, the majority of users using a single database shouldn't notice any differences and everything will continue to function as normal 🤞

I have a proof of concept currently working on a fork. Would there be any interest in possibly incorporating these changes if I can put together a PR?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions