Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-database support #9

Closed
copelco opened this issue Nov 16, 2021 · 2 comments
Closed

Multi-database support #9

copelco opened this issue Nov 16, 2021 · 2 comments

Comments

@copelco
Copy link

copelco commented Nov 16, 2021

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?

@mikicz
Copy link
Collaborator

mikicz commented Nov 17, 2021

Hi Colin,

I'd be happy to review, merge and release such a PR, if it's coded well (mainly meaning following the style of the project, adding tests and documentation) and no breaking changes are introduced (everything should remain as is for current users with just the default database).

I think there's also issues about this in the original repo (mypebble/django-pgviews#39, mypebble/django-pgviews#52) and there's also an unfinished PR for this in this repo (#1), so it seems a lot of people could use this!

copelco added a commit to copelco/django-pgviews that referenced this issue Nov 20, 2021
copelco added a commit to copelco/django-pgviews that referenced this issue Nov 20, 2021
copelco added a commit to copelco/django-pgviews that referenced this issue Nov 20, 2021
mikicz pushed a commit that referenced this issue Nov 22, 2021
@mikicz
Copy link
Collaborator

mikicz commented Nov 22, 2021

Implemented in #10, released as 0.8.0 to PyPI.

@mikicz mikicz closed this as completed Nov 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants