@@ -859,10 +859,15 @@ You can parse this output to make form fields show up with a red border and thei
859
859
860
860
Two forms of multi-tenancy are supported:
861
861
862
+ - Single database, where every table has a tenant column (using the "multiTenancy" middleware).
863
+ - Multi database, where every tenant has it's own database (using the "reconnect" middleware).
864
+
865
+ Below is an explanation of the corresponding middlewares.
866
+
862
867
#### Multi-tenancy middleware
863
868
864
- You may use the "multiTenancy" middleware when you have a multi-tenant database.
865
- If your tenants are identified by the "customer_id" column you can use the following handler:
869
+ You may use the "multiTenancy" middleware when you have a single multi-tenant database.
870
+ If your tenants are identified by the "customer_id" column, then you can use the following handler:
866
871
867
872
'multiTenancy.handler' => function ($operation, $tableName) {
868
873
return ['customer_id' => 12];
@@ -871,9 +876,21 @@ If your tenants are identified by the "customer_id" column you can use the follo
871
876
This construct adds a filter requiring "customer_id" to be "12" to every operation (except for "create").
872
877
It also sets the column "customer_id" on "create" to "12" and removes the column from any other write operation.
873
878
879
+ NB: You may want to retrieve the customer id from the session (the "$_ SESSION" variable).
880
+
874
881
#### Reconnect middleware
875
882
883
+ You may use the "reconnect" middleware when you have a separate database for each tenant.
884
+ If the tenant has it's own database named "customer_12", then you can use the following handler:
885
+
886
+ 'reconnect.databaseHandler' => function () {
887
+ return 'customer_12';
888
+ },
889
+
890
+ This will make the API reconnect to the database specifying "customer_12" as the database name. If you don't want
891
+ to use the same credentials, then you should also implement the "usernameHandler" and "passwordHandler".
876
892
893
+ NB: You may want to retrieve the database name from the session (the "$_ SESSION" variable).
877
894
878
895
### Prevent database scraping
879
896
0 commit comments