[Flask] Add, Change and Delete Models during runtime with flask-sqlalchemy and flask-migrate

Patrick Rieser zufaellig at outlook.com
Sat May 28 21:40:03 EDT 2016


Dear Anthony Ford,
thank you very much for your answer and sorry for my late reply (have been quite ill). I have to admit, that I never fully read up on blueprints. This seems to be quite a good and viable approach and should work well.
The thing is, I am curious now about runtime model alterations and I simply want to know in order to satisfy my curiousity how this can be accomplished - even if it goes unused. That being said, I realized that this should be a question for the SQLAlchemy mailing list.

Once more thank you very much and best whishes,Patrick


From: ford.anthonyj at gmail.com
Date: Mon, 16 May 2016 10:17:55 -0500
Subject: Re: [Flask] Add, Change and Delete Models during runtime with flask-sqlalchemy and flask-migrate
To: zufaellig at outlook.com
CC: flask at python.org

Would it not make more sense to run these as separate blueprints/apps? Dispatch to the appropriate blueprint and DB/model once logged in?
That seems like it would work for your application, and would require minimal re-writing/modding of the existing Flask/SQLAlchemy packages.Anthony Ford,
KF5IBN,ford.anthonyj at gmail.com

On Sun, May 15, 2016 at 3:45 PM, Patrick Rieser <zufaellig at outlook.com> wrote:



The purpose of this is that it would be possible then to serve multiple customers whose frontend overlaps mostly (the rest would be hidden behind feature locks), but where the table layout differs significantly from, a single application. "I don't think this would be possible, a restart is needed at some point to acknowledge the new models. Even if you do the changes directly in the DB, you'll start getting exceptions when the app tries to do stuff with things that no longer exist in your new models."The way I understand it (please correct me if I am wrong) is that the mapper in SQLAlchemy takes the module declaration and mapps it to a table which is stored at the metadata instance. So the plan would be to use manual mapping when a new table is created at runtime and to use metadata.remove to remove the table object from sqlalchemy.I think that one should in theory even be able to use the Table class from sqlalchemy core to define and register tables in as well as use metadata.remove to remove them on the fly and use alembic to do the changes in the database. But I have absolutely no clue if I would be able to still use flask-sqlalchemy which is no hard requirement, but makes thinks a lot easier.The problem is this goes way beyond my knowledge of flask-sqlalchmy (which as far as I know only wraps and extends sqlalchemy) and sqlalchemy in general, so I was looking for some pointers or help.Best wishes,PatrickDate: Sun, 15 May 2016 10:58:40 +0200Subject: Re: [Flask] Add, Change and Delete Models during runtime with flask-sqlalchemy and flask-migrateFrom: alejoar at gmail.comTo: zufaellig at outlook.comCC: flask at python.orgIf you change the models you are basically changing the app code.I don't think this would be possible, a restart is needed at some point to acknowledge the new models. Even if you do the changes directly in the DB, you'll start getting exceptions when the app tries to do stuff with things that no longer exist in your new models. What's the purpose of this? On May 15, 2016 04:31, "Patrick Rieser" <zufaellig at outlook.com> wrote:Hello everybody, so I try to add, change and delete Models during runtime with flask-sqlalchemy and flask-migrate . To do that I plan to write/change/delete the mymodel.py file, create the migration script and then do the migration. So far so good. The problem is that I don't know what internally happens in Flask and flask-sqlalchemy. I guess that there is at least some internal caching/dict to store additional information (like class names, fields etc.) that should be added/changed/cleared accordingly. Does anybody have any clue about this? Any help is greatly appreciated!  With kind regards,Patrick_______________________________________________Flask mailing listFlask at python.orghttps://mail.python.org/mailman/listinfo/flask 		 	   		  

_______________________________________________

Flask mailing list

Flask at python.org

https://mail.python.org/mailman/listinfo/flask



 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20160529/6ef6c759/attachment.html>


More information about the Flask mailing list