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

Patrick Rieser zufaellig at outlook.com
Sun May 15 16:45:44 EDT 2016


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 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20160515/ebfc9f39/attachment.html>


More information about the Flask mailing list