Database Tenancies

From Lianjapedia
Jump to: navigation, search

Database tenancies provide you with the ability to deploy an App once for multiple customers/tenants but have separate databases specific to each.

They are based on the authenticated user.

The database used by an App for a user in a specified tenancy is postfixed with an "_" followed by the tenancy (domain) for the user as specified in the Users workspace.

For example, if the database for an App is 'southwind' and the user's domain is 'xyzco' then the database for that user will be

southwind_xyzco

When the user authenticates in Desktop, Web or Mobile apps the specified database will be used rather than the default database for the App.

Remember to deploy the system!sysroles table and the database for the tenancy.

Note that if the specified domain contains '.' or '@' characters these are replaced with '_' characters.

e.g. with a domain of '@lianja.com' and an App that uses the southwind database, the tenancy database would be

southwind__lianja_com

A user with the default 'public' domain will use the database as specified in the App, e.g. 'southwind'.

You can copy a complete database to another using the COPY DATABASE command in the console or from the additional commands or context menu in the Data workspace.

The usertenancy() or userdomain() functions can be used in Lianja/VFP Server Pages (.rsp) and Lianja/VFP server-side procedures to determine the current user's domain.

Database Switcher

From Lianja v6.3, a Database Switcher can be added to a Page header.

This allows the user to select an alternative database.

By default, the database switcher is hidden, but it can be enabled by setting the Hide database switcher Page attribute to False.

The databases to be shown in the switcher are defined in a comma separated list in the Database switcher list App Setting.

The list can include '*' wildcards, e.g. southwind_*.

The App Database changed event delegate is called when the database is switched. It is called with one argument: the name of the new database. You can then adjust captions etc. for the new tenant/customer if required. Database metadata can be attached to the database to specify customer specific captions.

Database Switcher


Lianja v6.3 also allows an alternative database to be specified as an App parameter using the Lianja.openApp() method or in the App Tile URL.

See Also

App Center Tiles, Lianja.openApp(), Lianja.switchDatabase(), Runtime Database, Users and Roles, Users Workspace, USERDOMAIN(), USERTENANCY()