[sqlalchemy] Re: Documentation options

2019-03-29 Thread Xavier Bustamante Talavera
Hello Rich,

I use Dash  to read SQLAlchemy documentation, 
which is great to search through it and works offline (it downloads the 
whole docs).

Xavier.

El dijous, 21 març de 2019 21:20:33 UTC+1, Rich va escriure:
>
> Are there PDF versions of the docs available for downloading and reading? 
> I 
> don't find an answer on the web site. 
>
> TIA, 
>
> Rich 
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] user-defined simple fields in a multi-tenant flask app with ORM

2019-03-29 Thread Xavier Bustamante Talavera
Hello everyone and thanks for your answers,

>> Simpler solutions would be just using hstore or JSON types, but I would be 
>> loosing the goodies of SQLAlchemy / Postgres schemas and consistency.
> 
> this is totally how I'd want to do it unless your clients are given
> access to program in SQL and SQLAlchemy. What is a real-world
> scenario where you have given a tenant three additional columns on one
> of the database tables and the tenants need to use that data ?  what
> would that look like and what would you be doing that is any different
> from pulling those values from an hstore ?

@Mike: To answer you the user-defined data would only be used for CRUD 
operations, no specific coding logic involved, so the only benefit of going to 
using extra fields in a table rather than a hstore / json type would be data 
and access consistency —probably not enough for the problems you mention this 
approach would take.

As I understand then it is better to just define a Postgres JSON type as the 
custom field and provide our own schema validation.

For the client-defined inheritance, as those tables are going to lack custom 
logic more than the field definitions, we will value other approaches not 
touching table definitions.

> On 29 Mar 2019, at 00:32, Ibrahima Gaye  wrote:
> 
> Hi Jonathan,
> i would do it like this:
> - add in your global model  tables named attributs, attributs_value and 
> values,
> - any table (let's call it XTable) that will eventually has need extra column 
> per client will be linked to attributs_value via a table XTable_Attributs 
> (For maximum flexibility).
> Hope that helps,
> Best regards

@Ibrahima and @Jonathan, as I understand you are talking about something like 
the Entity–Attribute–Value model 
<https://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model>, 
adapted to the multi-tenant case. In my case the data comes form an API in 
JSON, so although there is not a special strong case towards this pattern, I 
think I will be using a JSON type.

Thank you again for your comments; it has been very enlightening!

> 
> 
> Ibrahima GAYE
> 
>  
> 
> 
> Le jeu. 28 mars 2019 à 21:14, Jonathan Vanasco  <mailto:jvana...@gmail.com>> a écrit :
> 
> 
> On Thursday, March 28, 2019 at 9:19:51 AM UTC-4, Mike Bayer wrote:
> 
> > Simpler solutions would be just using hstore or JSON types, but I would be 
> > loosing the goodies of SQLAlchemy / Postgres schemas and consistency. 
> 
> this is totally how I'd want to do it unless your clients are given access to 
> program in SQL and SQLAlchemy. 
> 
> wile I would handle this as JSON data too, there is also a database pattern 
> for doing this in multi tenant applications where you use a table to allocate 
> and store the allowable keys for each tenant , and another table to store the 
> key values for the tenants objects. but i would do this in JSON.
> 
> 
> 
> -- 
> SQLAlchemy - 
> The Python SQL Toolkit and Object Relational Mapper
>  
> http://www.sqlalchemy.org/ <http://www.sqlalchemy.org/>
>  
> To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve 
> <http://stackoverflow.com/help/mcve> for a full description.
> --- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com 
> <mailto:sqlalchemy+unsubscr...@googlegroups.com>.
> To post to this group, send email to sqlalchemy@googlegroups.com 
> <mailto:sqlalchemy@googlegroups.com>.
> Visit this group at https://groups.google.com/group/sqlalchemy 
> <https://groups.google.com/group/sqlalchemy>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.
> 
> -- 
> SQLAlchemy - 
> The Python SQL Toolkit and Object Relational Mapper
>  
> http://www.sqlalchemy.org/ <http://www.sqlalchemy.org/>
>  
> To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve 
> <http://stackoverflow.com/help/mcve> for a full description.
> --- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com 
> <mailto:sqlalchemy+unsubscr...@googlegroups.com>.
> To post to this group, send email to sqlalchemy@googlegroups.com 
> <mailto:sqlalchemy@googlegroups.com>.
> Visit this group at https://groups.go

[sqlalchemy] user-defined simple fields in a multi-tenant flask app with ORM

2019-03-28 Thread Xavier Bustamante Talavera
Hello,

Thanks in advance for the help.

I am using the ORM with SQLAlchemy in a flask app that is multi-tenant 
(multi-client): I have several running Flask apps, one per client. Each 
flask app connects to a different Postgres schema. I use one declarative 
base for all clients, as they share the same ORM classes, and then every 
time flask creates a new session it connects to the client schema. I create 
the tables using the ORM in python, in a way based in this 
issue: https://github.com/sqlalchemy/sqlalchemy/issues/3914

A new requirement is client-defined custom fields. So, our ORM classes will 
have their regularly defined fields in sqlalchemy ORM manner in python, 
plus some client-defined fields. The client-defined fields are regular 
types without difficult stuff: like strings, numbers... As every client is 
in its own schema, an example of approach could be creating those fields in 
the table in the db directly, and then reflect them on the ORM at the 
beginning of each session (as we need to know the schema). Simpler 
solutions would be just using hstore or JSON types, but I would be loosing 
the goodies of SQLAlchemy / Postgres schemas and consistency.

This could be done in different ways in SQLAlchemy, so I am asking you to 
orient me to a solution, guide, tutorial, or advice to avoid known pitfalls 
when doing this. For example some steps in how to build this reflection, if 
you think it is a good solution.

A future requirement will be creating client-defined tables that inherit 
from our regular ORM ones. If for example, we have "Computer" ORM class, 
they would want to define types of Computers, like "Desktop". These classes 
would only be collections of client-defined fields. How would this impact 
the above solution?

And finally, I will learn database migrations with Alembic, so any piece of 
advice or link to manage this with Alembic would be appreciated.

This is for open-source software, so if we manage to do it we are happy to 
write a blog post anywhere (we have a small blog site for example), if you 
find it can be useful for others.

Thank you for your time (and this amazing software)! :-)

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.