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

Anthony Ford ford.anthonyj at gmail.com
Mon May 16 11:17:55 EDT 2016


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,
> Patrick
>
>
>
> ------------------------------
> Date: Sun, 15 May 2016 10:58:40 +0200
> Subject: Re: [Flask] Add, Change and Delete Models during runtime with
> flask-sqlalchemy and flask-migrate
> From: alejoar at gmail.com
> To: zufaellig at outlook.com
> CC: flask at python.org
>
>
> If 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 list
> Flask at python.org
> https://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/20160516/1d87c02f/attachment-0001.html>


More information about the Flask mailing list