		      Sample multi-tenant database
		      ============================

This directory contains a script and supporting files for creating the sample multi-tenant database, named "sportsmt".

The script, named createdb (createdb.bat on Windows), needs access to all the files and subdirectories provided. You can either copy the contents of the samples/MultiTenancy/db directory to your working directory or run the script from within samples/MultiTenancy/db. The sportsmt database is created in your current directory.

Note that it is recommended that you first run the 'proenv' script located under the <Progress-install-dir>/bin directory so that the 'createdb' script can find the executables needed for building the database.

At the end, you will have a database with the following:

Multi-tenant tables: 
-------------------
- Customer
- Order
- Orderline
- Item

Shared table:
------------
- State


Tenants Domains and Users:
--------------------------

  Tenant       Type      Domain        User         Password
  ------       ----      ------        ----         --------
  Default      default   <blank>       <blank>      <blank>
  EastSports   regular   EastSports    EastSports   <blank>
  WestSports   regular   WestSports    WestSports   <blank>
  NorthSports  regular   NorthSports   NorthSports  <blank>
  SouthSports  regular   SouthSports   SouthSports  <blank>
  theSuper     super     theSuper      theSuper     <blank>


Group:
------

The database will contain a group named "groupItem" on the "Item" table, which contains the following tenants: EastSports, WestSports and SouthSports.


Setting user/tenancy:
---------------------

To set your user and tenancy, you can run the provided xsetuserid.p procedure from your ABL session, adjusting the parameters to the tenancy you want to set, based on the table described above. For example, assuming xsetuserid.p is in your PROPATH:

RUN xsetuserid.p ("SouthSports@SouthSports","SouthSports", "").

The above example sets the current user to the SouthSports user in the SouthSports domain.

In this sample database, the application is the trusted source of user authentication.

Loading process:
---------------

This is a brief description of the procedures executed during the loading process.

loaddb.p : this is the main driver procedure for loading the definitions, tenants and data into the database.

loaddf.p : loads the definitions from sportsmt.df into the database

gettens.p: main driver for creating tenants and group.

tenantCreate.p: procedure for creating tenants

getsuperten.p: procedure for creating a super tenant.

groupCreate.p: procedure for creating a group

groupTenantAdd.p : procedure for adding tenants to a group

xsetuserid.p: procedure for setting the user and tenancy, using a CLIENT-PRINCIPAL objet.

loadalldata.p: procedure that loads data into the tables for each tenant. The Item  table is part of a group and it is loaded only by one of the tenants in that group.
