[GH-ISSUE #86] Auto-discovery on multiple DBs #54

Open
opened 2026-02-26 01:33:00 +03:00 by kerem · 4 comments
Owner

Originally created by @ibstelix on GitHub (Mar 4, 2019).
Original GitHub issue: https://github.com/jeffknupp/sandman2/issues/86

Hello dear @all
I spent the whole day try to hack sandman2 to make it support multiple DBs via SQLALCHEMY_BINDS :)
I failed, any guidance to which path i should follow ?
I want provide SQLALCHEMY_BINDS intead (or in addition) of database_uri and autogenerate all the resources of the tables in SQLALCHEMY_BINDS DBs.... Lazyman here :(

Originally created by @ibstelix on GitHub (Mar 4, 2019). Original GitHub issue: https://github.com/jeffknupp/sandman2/issues/86 Hello dear @all I spent the whole day try to hack sandman2 to make it support multiple DBs via SQLALCHEMY_BINDS :) I failed, any guidance to which path i should follow ? I want provide SQLALCHEMY_BINDS intead (or in addition) of database_uri and autogenerate all the resources of the tables in SQLALCHEMY_BINDS DBs.... Lazyman here :(
Author
Owner

@jeffknupp commented on GitHub (Mar 8, 2019):

This is technically possible but would require a decent amount of development work. I'll need to do a bit more research into what would be required.

<!-- gh-comment-id:471070931 --> @jeffknupp commented on GitHub (Mar 8, 2019): This is technically possible but would require a decent amount of development work. I'll need to do a bit more research into what would be required.
Author
Owner

@ibstelix commented on GitHub (Mar 9, 2019):

Thank you that will make it even greater 👍

<!-- gh-comment-id:471145352 --> @ibstelix commented on GitHub (Mar 9, 2019): Thank you that will make it even greater :+1:
Author
Owner

@Carelvd commented on GitHub (Nov 5, 2019):

@ibstelix I presently have a similar need, my fork, and associated PR, refactor Sandman 2 into a structure that might be easier to hack upon.

The SQLAclhemy invocation under the database.py file needs to be converted into a factory method of sorts, or it must be included within the application factory under app.py as I understand it. The Admin instantiation, under administration.py, works similarly as I understand it.

The trick, however, involves providing an instance of SQLAclhemy during the creation of AutomapModel such that users may subclass the latter to override the models/tables of interest to them. Since SQLAlchemy seems to bind the two together it becomes a bit dicy and one essentially has to make the two instances globally available. This is fine for a single DB and associated instances of SQLAclhemy and AutomapModel and is presently done in Sandman 2. In my refactoring I think I've gotten the structure correct to allow for multiple databases by creating a model first before creating the declarative base; which is then used to create the deferred base/AutomapModel.

class Model(object) : 
   ...

DeclarativeModel = declarative_base(cls=(db.Model, Model), name="AutomapModel")
AutomapModel = automap_base(DeclarativeModel)

It now becomes possible for users to subclass Model and then for use to invoke the latter methods within the app factory, once per database. I am still setting up to try this however.

<!-- gh-comment-id:550063496 --> @Carelvd commented on GitHub (Nov 5, 2019): @ibstelix I presently have a similar need, my [fork](https://github.com/manaikan/sandman2), and associated PR, refactor Sandman 2 into a structure that might be easier to hack upon. The ``SQLAclhemy`` invocation under the `database.py` file needs to be converted into a factory method of sorts, or it must be included within the ``application`` factory under ``app.py`` as I understand it. The ``Admin`` instantiation, under ``administration.py``, works similarly as I understand it. The trick, however, involves providing an instance of ``SQLAclhemy`` during the creation of ``AutomapModel`` such that users may subclass the latter to override the models/tables of interest to them. Since SQLAlchemy seems to bind the two together it becomes a bit dicy and one essentially has to make the two instances globally available. This is fine for a single DB and associated instances of ``SQLAclhemy`` and ``AutomapModel`` and is presently done in Sandman 2. In my refactoring I think I've gotten the structure correct to allow for multiple databases by creating a model first before creating the declarative base; which is then used to create the deferred base/AutomapModel. class Model(object) : ... DeclarativeModel = declarative_base(cls=(db.Model, Model), name="AutomapModel") AutomapModel = automap_base(DeclarativeModel) It now becomes possible for users to subclass Model and then for use to invoke the latter methods within the app factory, once per database. I am still setting up to try this however.
Author
Owner

@Pmoshbr commented on GitHub (Dec 3, 2021):

Any news ?? How to allow multiples databases at a single instance of sandman2 ??

<!-- gh-comment-id:985182846 --> @Pmoshbr commented on GitHub (Dec 3, 2021): Any news ?? How to allow multiples databases at a single instance of sandman2 ??
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/sandman2-jeffknupp#54
No description provided.