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

schema = ModelSchema.objects.db_manager(DB_NAME).create(name=instance.schema) #25

Open
mmichealjroberts opened this issue Jul 17, 2020 · 6 comments
Labels
feature New feature or request question Further information is requested

Comments

@mmichealjroberts
Copy link

I was wondering.

What would be really awesome for me is to be able to use something like:

schema = ModelSchema.objects.db_manager(DB_NAME).create(name=instance.schema)

Is there anything theoretically stopping me from using this approach?

@mmichealjroberts
Copy link
Author

If you would like, email me hello@asencis.com and we can talk about a small amount of project work if you want to help us achieve this goal.

@rvinzent
Copy link
Owner

rvinzent commented Jul 18, 2020

Hi, would you be able to clarify the feature request a bit? Are you looking to have the schema table in a different database than the generated tables?

I don't believe this is currently possible in the current implementation because each generated table holds an FK to the schema record.

The current implementation is pretty inefficient though, and I hope to refactor that away to have minimal performance impact when using dynamic models.

I think this feature should be possible to implement once that blocker is removed. I would definitely be willing to collaborate on something like this, I appreciate any work you and your team might be able to contribute! 🙂

It would be great to know more about the feature and help spec out an API. I can write up some tickets with the work required. There are some other features requested for v0.3 on the roadmap as well that I hope to add before the next release.

I should note that I would not yet consider this package suitable for production or business critical data, and there is not a guarantee of a backwards compatible API pre-1.0. I do hope to bring it to that point, but we are a ways off from the stability, performance, and features that I hope to achieve. Thanks!

@rvinzent rvinzent added the feature New feature or request label Jul 18, 2020
@mmichealjroberts
Copy link
Author

Hi @rvinzent , many thanks for the considered reply - appreciated.

So for me, I have bolted on a workaround which creates the ModelSchema and FieldSchema table migrations in a target db at runtime, then db_manager() allows me to spoecify the same target DB for ModelSchema and FieldSchema to be created in - then I have modified various chain calls after as_model() to target the same DB for dynamic model creation. It would be really nice to somehow call the dynamic instance of the class asCar.db_manager('db_name').as_model() but currently, this does not work.

At the minute I'm storing the db_name as a variable on the ModelSchema and FieldSchema objects - schema = ModelSchema.objects.create(name=instance.schema, db_name=DB_NAME) then this is the db target what is called further down the chain when invoking as_model(). However, this is not "Django" per se, and should really be called as schema = ModelSchema.objects.db_manager('db_name').create(name=instance.schema)...

@rvinzent
Copy link
Owner

rvinzent commented Aug 5, 2020

Sounds like a useful feature to me! I know that Django has pretty good support for connecting to different databases so I would like to use Django's existing functionality as much as possible.

To clarify, the ask here would be to be able to have the schema models live in a separate database than the generated tables?

@mmichealjroberts
Copy link
Author

I'd like to be able to specify different dynamic datasets to different databases, yes! :) Could I email you if possible to come on to our team?

@rvinzent
Copy link
Owner

rvinzent commented Sep 21, 2020

Hi @michealjroberts, I looked into this a bit more, and it seems like you'll probably be able to do what you want with either the using parameter of the save() method, or this database routers feature looks to be very useful.

Or are you looking to create databases at runtime?

@rvinzent rvinzent added the question Further information is requested label Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants