diff --git a/README.md b/README.md index 79a6dca4..0fd881a7 100644 --- a/README.md +++ b/README.md @@ -340,7 +340,35 @@ Note that deleting a tenant doesn't delete his database. You can do this manuall ## Storage driver -Currently, only Redis is supported, but you're free to code your own storage driver which follows the `Stancl\Tenancy\Interfaces\StorageDriver` interface. Just point the `tenancy.storage_driver` setting at your driver. +### Database + +The database storage driver lets you store information about tenants in a relational database like MySQL, PostgreSQL and SQLite. + +To use this storage driver, publish the `create_tenants_table` migration: + +``` +php artisan vendor:publish --provider='Stancl\Tenancy\TenancyServiceProvider' --tag=migrations +``` + +By default, the table contains only `uuid`, `domain` and `data` columns. + +The `data` column is used to store information about a tenant, such as their selected plan, in JSON form. This package does not store anything in the column by default. + +You can store specific keys in your own columns. This is useful if you want to use RDBMS features like indexes. + +If you don't need any custom columns, you can skip the next section and run: + +``` +php artisan migrate +``` + +#### Adding your own columns + +To add your own columns, TODO. + +### Redis + +Using Redis as your storage driver is recommended due to its low overhead compared to a relational database like MySQL. **Note that you need to configure persistence on your Redis instance** if you don't want to lose all information about tenants. diff --git a/src/Tenant.php b/src/Tenant.php index c91341e6..7b24e4dc 100644 --- a/src/Tenant.php +++ b/src/Tenant.php @@ -7,8 +7,8 @@ use Stancl\Tenancy\Interfaces\TenantModel; class Tenant extends Model implements TenantModel { - protected $dataColumn = 'data'; - protected $specialColumns = []; + protected $dataColumn = 'data'; // todo load this from config + protected $specialColumns = []; // todo load this from config protected $guarded = []; protected $primaryKey = 'uuid'; public $incrementing = false; diff --git a/src/assets/config.php b/src/assets/config.php index c742da84..0c2944aa 100644 --- a/src/assets/config.php +++ b/src/assets/config.php @@ -1,14 +1,14 @@ 'Stancl\Tenancy\StorageDrivers\RedisStorageDriver', + 'storage_driver' => 'Stancl\Tenancy\StorageDrivers\DatabaseStorageDriver', 'tenant_model' => 'Stancl\Tenancy\Tenant', 'tenant_route_namespace' => 'App\Http\Controllers', 'exempt_domains' => [ // 'localhost', ], 'database' => [ - 'based_on' => 'mysql', + 'based_on' => 'sqlite', 'prefix' => 'tenant', 'suffix' => '', ],