Hi Massimo

My thought/suggestions are:

Almost everyone using this feature will also wish to keep data
relating to the tenant,  e.g. they will have a 'tenant' table with
information about 'harvard.school.org'.

The foreign key relating to the 'tenant' table under your system would
therefore be using the string 'harvard.school.org' rather than an id
integer.  Is that a good idea?

Many webservers will accept any sub-domain and this could lead to the
field 'request_tenant' being populated with misspellings etc,
e.g.   'harvd.school.org' or 'harverd.school.org',
'harvhard.school.org'.  This would be difficult to relate to a
'tenant' table.

To stop those problems,  you might still consider to use the ideas in
my original suggestion,  i.e.
* lookup the sub-domain when the request is received and allocate an
id reference.
* specify what to do if the sub-domain is not recognised i.e. provide
a default value or raise an error (maybe 404).
* to save time when it is a single tenant system,  set a global
constant to avoid the overhead of the multi-tenant lookup.

Regards,
David

On May 26, 3:10 pm, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:
> I changed 'request_precinct' to 'request_tenant' since this is more
> appropriate. We are talking about buildig multi-tenant apps.
>
> db._common_fields=[Field('request_tenant',default=request.env.http_host,w
> ritable=False,readable=False)]
>
> Notice you can also do
>
> db._common_fields=[auth.signature]
>
> and all tables will have created_by, modified_by, created_on,
> modified_on, etc.
>
> On May 26, 7:17 am, Massimo Di Pierro <massimo.dipie...@gmail.com>
> wrote:
>
>
>
>
>
>
>
> > yes.
>
> > On May 25, 11:37 pm, mattgorecki <m...@goelephant.com> wrote:
>
> > > So in this example request_precinct would equal harvard.anyschool.org?
>
> > > Matt
>
> > > On May 25, 9:47 pm, Massimo Di Pierro <massimo.dipie...@gmail.com>
> > > wrote:
>
> > > > There are two more features in trunk that I could use some testing
> > > > with (common fields and precints)
>
> > > > Imagine you have created an app "school" designed to manage one
> > > > school. It has one database and many tables. You wrote it with one
> > > > school in mind. Now you want to turn it into a service so that
> > > > multiple schools can register and use it. You want to identify the
> > > > school for example by the urlhttp://harvard.anyschool.organdeach
> > > > school should ONLY see its own users, groups, records, etc. etc.
>
> > > > Before today to do this you would have to rewrite all your tables and
> > > > queries.
>
> > > > Today you can do it without changing your code at all. You just have
> > > > to add this line after db=DAL(...)
>
> > > > db._common_fields=[Field('request_precinct',default=request.env.http_host,w
> > > >  ritable=False,readable=False)]
>
> > > > Yes. That is it!
>
> > > > How does it work?
>
> > > > 1) db._common_fields is a list of fields that you want to add to all
> > > > tables.
> > > > 2) The field called 'request_precinct' is special. Every query
> > > > involving a table having this field is automatically filtered byfield
> > > > value == field default. In our example the default is
> > > > request.env.http_host, i.e. the hostname in the http request which
> > > > identifies the school.
> > > > 3) The field is hidden (writable=False,readable=False) but has a
> > > > default therefore it is automatically set for all inserts.
>
> > > > There is nothing special about schools here. You can use it with any
> > > > other app.
>
> > > > Give it a try and let me know.
>
> > > > I could use some help in writing some documentation about the new
> > > > features added today. ;-)
>
> > > > Massimo

Reply via email to