<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'><div>Dear Anthony Ford,</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div><br></div><div>Once more thank you very much and best whishes,</div><div>Patrick</div><div><br></div><br><br><div><hr id="stopSpelling">From: ford.anthonyj@gmail.com<br>Date: Mon, 16 May 2016 10:17:55 -0500<br>Subject: Re: [Flask] Add, Change and Delete Models during runtime with flask-sqlalchemy and flask-migrate<br>To: zufaellig@outlook.com<br>CC: flask@python.org<br><br><div dir="ltr">Would it not make more sense to run these as separate blueprints/apps? Dispatch to the appropriate blueprint and DB/model once logged in?<div><br></div><div>That seems like it would work for your application, and would require minimal re-writing/modding of the existing Flask/SQLAlchemy packages.</div></div><div class="ecxgmail_extra"><br clear="all"><div><div class="ecxgmail_signature"><div dir="ltr">Anthony Ford,<br>KF5IBN,<div><a href="mailto:ford.anthonyj@gmail.com" target="_blank">ford.anthonyj@gmail.com</a></div></div></div></div>
<br><div class="ecxgmail_quote">On Sun, May 15, 2016 at 3:45 PM, Patrick Rieser <span dir="ltr"><<a href="mailto:zufaellig@outlook.com" target="_blank">zufaellig@outlook.com</a>></span> wrote:<br><blockquote class="ecxgmail_quote" style="border-left:1px #ccc solid;padding-left:1ex;">


<div><div dir="ltr"><div dir="ltr" style="line-height:21.299999237060547px;color:rgb(68,68,68);font-size:15px;">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. </div><span><div dir="ltr" style="line-height:21.299999237060547px;color:rgb(68,68,68);font-size:15px;"><br style="line-height:21.299999237060547px;"></div><div dir="ltr" style="line-height:21.299999237060547px;color:rgb(68,68,68);font-size:15px;">"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."</div><div dir="ltr" style="line-height:21.299999237060547px;color:rgb(68,68,68);font-size:15px;"><br style="line-height:21.299999237060547px;"></div><div dir="ltr" style="line-height:21.299999237060547px;color:rgb(68,68,68);font-size:15px;"><br style="line-height:21.299999237060547px;"></div></span><div dir="ltr" style="line-height:21.299999237060547px;color:rgb(68,68,68);font-size:15px;">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.</div><div dir="ltr" style="line-height:21.299999237060547px;color:rgb(68,68,68);font-size:15px;"><br style="line-height:21.299999237060547px;"></div><div dir="ltr" style="line-height:21.299999237060547px;color:rgb(68,68,68);font-size:15px;">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.</div><div dir="ltr" style="line-height:21.299999237060547px;color:rgb(68,68,68);font-size:15px;"><br style="line-height:21.299999237060547px;"></div><div dir="ltr" style="line-height:21.299999237060547px;color:rgb(68,68,68);font-size:15px;">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.</div><div dir="ltr" style="line-height:21.299999237060547px;color:rgb(68,68,68);font-size:15px;"><br style="line-height:21.299999237060547px;"></div><div dir="ltr" style="line-height:21.299999237060547px;color:rgb(68,68,68);font-size:15px;"><br style="line-height:21.299999237060547px;"></div><div dir="ltr" style="line-height:21.299999237060547px;color:rgb(68,68,68);font-size:15px;">Best wishes,</div><div dir="ltr" style="line-height:21.299999237060547px;color:rgb(68,68,68);font-size:15px;">Patrick<br style="line-height:21.299999237060547px;"><br style="line-height:21.299999237060547px;"><br style="line-height:21.299999237060547px;"><br style="line-height:21.299999237060547px;"><div style="line-height:21.299999237060547px;"><hr style="line-height:21.299999237060547px;">Date: Sun, 15 May 2016 10:58:40 +0200<br style="line-height:21.299999237060547px;">Subject: Re: [Flask] Add, Change and Delete Models during runtime with flask-sqlalchemy and flask-migrate<br style="line-height:21.299999237060547px;">From: <a href="mailto:alejoar@gmail.com" target="_blank">alejoar@gmail.com</a><br style="line-height:21.299999237060547px;">To: <a href="mailto:zufaellig@outlook.com" target="_blank">zufaellig@outlook.com</a><br style="line-height:21.299999237060547px;">CC: <a href="mailto:flask@python.org" target="_blank">flask@python.org</a><div><div class="h5"><br style="line-height:21.299999237060547px;"><br style="line-height:21.299999237060547px;"><p dir="ltr" style="line-height:21.299999237060547px;">If you change the models you are basically changing the app code.</p><p dir="ltr" style="line-height:21.299999237060547px;">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. </p><p dir="ltr" style="line-height:21.299999237060547px;">What's the purpose of this? </p><div style="line-height:21.299999237060547px;">On May 15, 2016 04:31, "Patrick Rieser" <<a href="mailto:zufaellig@outlook.com" style="line-height:21.299999237060547px;color:rgb(0,104,207);" target="_blank">zufaellig@outlook.com</a>> wrote:<br style="line-height:21.299999237060547px;"><blockquote style="line-height:21.299999237060547px;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex;"><div style="line-height:21.299999237060547px;"><div dir="ltr" style="line-height:21.299999237060547px;"><div style="line-height:21.299999237060547px;"><div style="line-height:21.299999237060547px;">Hello everybody,</div><div style="line-height:21.299999237060547px;"> </div><div style="line-height:21.299999237060547px;">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!</div><div style="line-height:21.299999237060547px;"> </div><div style="line-height:21.299999237060547px;"> </div><div style="line-height:21.299999237060547px;">With kind regards,</div><div style="line-height:21.299999237060547px;">Patrick</div></div></div></div><br style="line-height:21.299999237060547px;">_______________________________________________<br style="line-height:21.299999237060547px;">Flask mailing list<br style="line-height:21.299999237060547px;"><a href="mailto:Flask@python.org" style="line-height:21.299999237060547px;color:rgb(0,104,207);" target="_blank">Flask@python.org</a><br style="line-height:21.299999237060547px;"><a href="https://mail.python.org/mailman/listinfo/flask" rel="noreferrer" style="line-height:21.299999237060547px;color:rgb(0,104,207);" target="_blank">https://mail.python.org/mailman/listinfo/flask</a></blockquote></div></div></div></div></div>                                          </div></div>
<br>_______________________________________________<br>
Flask mailing list<br>
<a href="mailto:Flask@python.org">Flask@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/flask" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/flask</a><br>
<br></blockquote></div><br></div></div>                                       </div></body>
</html>