mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 11:14:04 +00:00
* Add readied tenants Add config for readied tenants Add `create` and `clear` command Add Readied scope and static functions Add tests * Fix initialize function name * Add readied events * Fix readied column cast * Laravel 6 compatible * Add readied scope tests * Rename config from include_in_scope to include_in_queries * Change terminology to pending * Update CreatePendingTenants.php * Laravel 6 compatible * Update CreatePendingTenants.php * runForMultiple can scope pending tenants * Fix issues * Code and comment style improvements * Change 'tenant' to 'tenants' in command signature * Fix code style (php-cs-fixer) * Rename variables in CreatePendingTenants * Remove withPending from runForMultiple * Update tenants option trait * Update command that use tenants * Fix code style (php-cs-fixer) * Improve getTenants condition * Update config comments * Minor config comment corrections * Grammar fix * Update comments and naming * Correct comments * Improve writing * Remove pending tenant clearing time constraints * Allow using only one time constraint for clearing the pending tenants * phpunit to pest * Fix code style (php-cs-fixer) * Fix code style (php-cs-fixer) * [4.x] Optionally delete storage after tenant deletion (#938) * Add test for deleting storage after tenant deletion * Save `storage_path()` in a variable after initializing tenant in test Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com> * Add DeleteTenantStorage listener * Update test name * Remove storage deletion config key * Remove tenant storage deletion events * Move tenant storage deletion to the DeletingTenant event Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com> * [4.x] Finish incomplete and missing tests (#947) * complete test sqlite manager customize path * complete test seed command works * complete uniqe exists test * Update SingleDatabaseTenancyTest.php * refactor the ternary into if condition * custom path * simplify if condition * random dir name * Update SingleDatabaseTenancyTest.php * Update CommandsTest.php * prefix random DB name with custom_ Co-authored-by: Samuel Štancl <samuel@archte.ch> * [4.x] Add batch tenancy queue bootstrapper (#874) * exclude master from CI * Add batch tenancy queue bootstrapper * add test case * skip tests for old versions * variable docblocks * use Laravel's connection getter and setter * convert test to pest * bottom space * singleton regis in TestCase * Update src/Bootstrappers/BatchTenancyBootstrapper.php Co-authored-by: Samuel Štancl <samuel@archte.ch> * convert batch class resolution to property level * enabled BatchTenancyBootstrapper by default * typehint DatabaseBatchRepository * refactore name * DI DB manager * typehint * Update config.php * use initialize() twice without end()ing tenancy to assert that previousConnection logic works correctly Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com> Co-authored-by: Abrar Ahmad <abrar.dev99@gmail.com> Co-authored-by: Samuel Štancl <samuel@archte.ch> * [4.x] Storage::url() support (modified #689) (#909) * This adds support for tenancy aware Storage::url() method * Trigger CI build * Fixed Link command for Laravel v6, added StorageLink Events, more StorageLink tests, added RemoveStorageSymlinks Job, added Storage Jobs to TenancyServiceProvider stub, renamed misleading config example. * Fix typo * Fix code style (php-cs-fixer) * Update config comments * Format code in Link command, make writing more concise * Change "symLinks" to "symlinks" * Refactor Link command * Fix test name typo * Test fetching files using the public URL * Extract Link command logic into actions * Fix code style (php-cs-fixer) * Check if closure is null in CreateStorageSymlinksAction * Stop using command terminology in CreateStorageSymlinksAction * Separate the Storage::url() test cases * Update url_override comments * Remove afterLink closures, add types, move actions, add usage explanation to the symlink trait * Fix code style (php-cs-fixer) * Update public storage URL test * Fix issue with using str() * Improve url_override comment, add todos * add todo comment * fix docblock style * Add link command tests back * Add types to $tenants in the action handle() methods * Fix typo, update variable name formatting * Add tests for the symlink actions * Change possibleTenantSymlinks not to prefix the paths twice while tenancy is initialized * Fix code style (php-cs-fixer) * Stop testing storage directory existence in symlink test * Don't specify full namespace for Tenant model annotation * Don't specify full namespace in ActionTest * Remove "change to DI" todo * Remove possibleTenantSymlinks return annotation * Remove symlink-related jobs, instantiate and use actions * Revert "Remove symlink-related jobs, instantiate and use actions" This reverts commit547440c887. * Add a comment line about the possible tenant symlinks * Correct storagePath and publicPath variables * Revert "Correct storagePath and publicPath variables" This reverts commite3aa8e2086. * add a todo Co-authored-by: Martin Vlcek <martin@dontfreakout.eu> Co-authored-by: lukinovec <lukinovec@gmail.com> Co-authored-by: PHP CS Fixer <phpcsfixer@example.com> * Use HasTenantOptions in Link * Correct the tenant order in Run command * Fix code style (php-cs-fixer) * Fix formatting issue * Add missing imports * Fix code style (php-cs-fixer) * Use HasTenantOptions instead of the old trait name in Up/Down commands * Fix test name typo * Remove redundant passing of $withPending to runForMultiple in TenantCollection's runForEach * Make `with-pending` default to `config('tenancy.pending.include_in_queries')` in HasTenantOptions * Make `createPending()` return the created tenant * Fix code style (php-cs-fixer) * Remove tenant ordering * Fix code style (php-cs-fixer) * Remove duplicate tenancy bootstrappers config setting * Add and use getWithPendingOption method * Fix code style (php-cs-fixer) * Add optionNotPassedValue property * Test using --with-pending and the include_in_queries config value * Make with-pending VALUE_NONE * use plural in test names * fix test names * add pullPendingTenantFromPool * Add docblock type * Import commands * Fix code style (php-cs-fixer) * Move pending tenant tests to a more appropriate file * Delete queuetest from gitignore * Delete queuetest file * Add queuetest to gitignore * Rename pullPendingTenant to pullPending and don't pass bool to that method * Add a test that checks if pulling a pending tenant removes it from the pool * bump stancl/virtualcolumn to ^1.3 * Update pending tenant pulling test * Dynamically get columns for pending queries * Dynamically get virtual column name in ClearPendingTenants * Fix ClearPendingTenants bug * Make test name more accurate * Update test name * add a todo * Update include in queries test name * Remove `Tenant::query()->delete()` from pending tenant check test * Rename the pending tenant check test name * Update HasPending.php * fix all() call * code style * all() -> get() * Remove redundant `Tenant::all()` call Co-authored-by: j.stein <joristein@gmail.com> Co-authored-by: lukinovec <lukinovec@gmail.com> Co-authored-by: PHP CS Fixer <phpcsfixer@example.com> Co-authored-by: Abrar Ahmad <abrar.dev99@gmail.com> Co-authored-by: Riley19280 <rileyaven88@gmail.com> Co-authored-by: Martin Vlcek <martin@dontfreakout.eu>
304 lines
12 KiB
PHP
304 lines
12 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Stancl\Tenancy\Middleware;
|
|
use Stancl\Tenancy\Resolvers;
|
|
|
|
return [
|
|
'tenant_model' => Stancl\Tenancy\Database\Models\Tenant::class,
|
|
'domain_model' => Stancl\Tenancy\Database\Models\Domain::class,
|
|
|
|
'id_generator' => Stancl\Tenancy\UUIDGenerator::class,
|
|
|
|
/**
|
|
* The list of domains hosting your central app.
|
|
*
|
|
* Only relevant if you're using the domain or subdomain identification middleware.
|
|
*/
|
|
'central_domains' => [
|
|
'127.0.0.1',
|
|
'localhost',
|
|
],
|
|
|
|
'identification' => [
|
|
/**
|
|
* The default middleware used for tenant identification.
|
|
*
|
|
* If you use multiple forms of identification, you can set this to the "main" approach you use.
|
|
*/
|
|
'default_middleware' => Middleware\InitializeTenancyByDomain::class,// todo@identification add this to a 'tenancy' mw group
|
|
|
|
/**
|
|
* All of the identification middleware used by the package.
|
|
*
|
|
* If you write your own, make sure to add them to this array.
|
|
*/
|
|
'middleware' => [
|
|
Middleware\InitializeTenancyByDomain::class,
|
|
Middleware\InitializeTenancyBySubdomain::class,
|
|
Middleware\InitializeTenancyByDomainOrSubdomain::class,
|
|
Middleware\InitializeTenancyByPath::class,
|
|
Middleware\InitializeTenancyByRequestData::class,
|
|
],
|
|
|
|
/**
|
|
* Tenant resolvers used by the package.
|
|
*
|
|
* Resolvers which implement the CachedTenantResolver contract have options for configuring the caching details.
|
|
* If you add your own resolvers, do not add the 'cache' key unless your resolver is based on CachedTenantResolver.
|
|
*/
|
|
'resolvers' => [
|
|
Resolvers\DomainTenantResolver::class => [
|
|
'cache' => false,
|
|
'cache_ttl' => 3600, // seconds
|
|
'cache_store' => null, // default
|
|
],
|
|
Resolvers\PathTenantResolver::class => [
|
|
'tenant_parameter_name' => 'tenant',
|
|
|
|
'cache' => false,
|
|
'cache_ttl' => 3600, // seconds
|
|
'cache_store' => null, // default
|
|
],
|
|
Resolvers\RequestDataTenantResolver::class => [
|
|
'cache' => false,
|
|
'cache_ttl' => 3600, // seconds
|
|
'cache_store' => null, // default
|
|
],
|
|
],
|
|
|
|
// todo@docs update integration guides to use Stancl\Tenancy::defaultMiddleware()
|
|
],
|
|
|
|
/**
|
|
* Tenancy bootstrappers are executed when tenancy is initialized.
|
|
* Their responsibility is making Laravel features tenant-aware.
|
|
*
|
|
* To configure their behavior, see the config keys below.
|
|
*/
|
|
'bootstrappers' => [
|
|
Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper::class,
|
|
Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper::class,
|
|
Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper::class,
|
|
Stancl\Tenancy\Bootstrappers\QueueTenancyBootstrapper::class,
|
|
Stancl\Tenancy\Bootstrappers\BatchTenancyBootstrapper::class,
|
|
// Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper::class, // Note: phpredis is needed
|
|
],
|
|
|
|
|
|
/**
|
|
* Pending tenants config.
|
|
* This is useful if you're looking for a way to always have a tenant ready to be used.
|
|
*/
|
|
'pending' => [
|
|
/**
|
|
* If disabled, pending tenants will be excluded from all tenant queries.
|
|
* You can still use ::withPending(), ::withoutPending() and ::onlyPending() to include or exclude the pending tenants regardless of this setting.
|
|
* Note: when disabled, this will also ignore pending tenants when running the tenant commands (migration, seed, etc.)
|
|
*/
|
|
'include_in_queries' => true,
|
|
/**
|
|
* Defines how many pending tenants you want to have ready in the pending tenant pool.
|
|
* This depends on the volume of tenants you're creating.
|
|
*/
|
|
'count' => env('TENANCY_PENDING_COUNT', 5),
|
|
],
|
|
|
|
/**
|
|
* Database tenancy config. Used by DatabaseTenancyBootstrapper.
|
|
*/
|
|
'database' => [
|
|
'central_connection' => env('DB_CONNECTION', 'central'),
|
|
|
|
/**
|
|
* Connection used as a "template" for the dynamically created tenant database connection.
|
|
* Note: don't name your template connection tenant. That name is reserved by package.
|
|
*/
|
|
'template_tenant_connection' => null,
|
|
|
|
/**
|
|
* The name of the temporary connection used for creating and deleting tenant databases.
|
|
*/
|
|
'tenant_host_connection_name' => 'tenant_host_connection',
|
|
|
|
/**
|
|
* Tenant database names are created like this:
|
|
* prefix + tenant_id + suffix.
|
|
*/
|
|
'prefix' => 'tenant',
|
|
'suffix' => '',
|
|
|
|
/**
|
|
* TenantDatabaseManagers are classes that handle the creation & deletion of tenant databases.
|
|
*/
|
|
'managers' => [
|
|
'sqlite' => Stancl\Tenancy\Database\TenantDatabaseManagers\SQLiteDatabaseManager::class,
|
|
'mysql' => Stancl\Tenancy\Database\TenantDatabaseManagers\MySQLDatabaseManager::class,
|
|
'pgsql' => Stancl\Tenancy\Database\TenantDatabaseManagers\PostgreSQLDatabaseManager::class,
|
|
'sqlsrv' => Stancl\Tenancy\Database\TenantDatabaseManagers\MicrosoftSQLDatabaseManager::class,
|
|
|
|
/**
|
|
* Use this database manager for MySQL to have a DB user created for each tenant database.
|
|
* You can customize the grants given to these users by changing the $grants property.
|
|
*/
|
|
// 'mysql' => Stancl\Tenancy\Database\TenantDatabaseManagers\PermissionControlledMySQLDatabaseManager::class,
|
|
|
|
/**
|
|
* Disable the pgsql manager above, and enable the one below if you
|
|
* want to separate tenant DBs by schemas rather than databases.
|
|
*/
|
|
// 'pgsql' => Stancl\Tenancy\Database\TenantDatabaseManagers\PostgreSQLSchemaManager::class, // Separate by schema instead of database
|
|
],
|
|
|
|
// todo docblock
|
|
'drop_tenant_databases_on_migrate_fresh' => false,
|
|
],
|
|
|
|
/**
|
|
* Cache tenancy config. Used by CacheTenancyBootstrapper.
|
|
*
|
|
* This works for all Cache facade calls, cache() helper
|
|
* calls and direct calls to injected cache stores.
|
|
*
|
|
* Each key in cache will have a tag applied on it. This tag is used to
|
|
* scope the cache both when writing to it and when reading from it.
|
|
*
|
|
* You can clear cache selectively by specifying the tag.
|
|
*/
|
|
'cache' => [
|
|
'tag_base' => 'tenant', // This tag_base, followed by the tenant_id, will form a tag that will be applied on each cache call.
|
|
],
|
|
|
|
/**
|
|
* Filesystem tenancy config. Used by FilesystemTenancyBootstrapper.
|
|
* https://tenancyforlaravel.com/docs/v3/tenancy-bootstrappers/#filesystem-tenancy-boostrapper.
|
|
*/
|
|
'filesystem' => [
|
|
/**
|
|
* Each disk listed in the 'disks' array will be suffixed by the suffix_base, followed by the tenant_id.
|
|
*/
|
|
'suffix_base' => 'tenant',
|
|
'disks' => [
|
|
'local',
|
|
'public',
|
|
// 's3',
|
|
],
|
|
|
|
/**
|
|
* Use this for local disks.
|
|
*
|
|
* See https://tenancyforlaravel.com/docs/v3/tenancy-bootstrappers/#filesystem-tenancy-boostrapper
|
|
*/
|
|
'root_override' => [
|
|
// Disks whose roots should be overriden after storage_path() is suffixed.
|
|
'local' => '%storage_path%/app/',
|
|
'public' => '%storage_path%/app/public/',
|
|
],
|
|
|
|
/*
|
|
* Tenant-aware Storage::disk()->url() can be enabled for specific local disks here
|
|
* by mapping the disk's name to a name with '%tenant_id%' (this will be used as the public name of the disk).
|
|
* Doing that will override the disk's default URL with a URL containing the current tenant's key.
|
|
*
|
|
* For example, Storage::disk('public')->url('') will return https://your-app.test/storage/ by default.
|
|
* After adding 'public' => 'public-%tenant_id%' to 'url_override',
|
|
* the returned URL will be https://your-app.test/public-1/ (%tenant_id% gets substitued by the current tenant's ID).
|
|
*
|
|
* Use `php artisan tenants:link` to create a symbolic link from the tenant's storage to its public directory.
|
|
*/
|
|
'url_override' => [
|
|
// Note that the local disk you add must exist in the tenancy.filesystem.root_override config
|
|
// todo@v4 Rename %tenant_id% to %tenant_key%
|
|
// todo@v4 Rename url_override to something that describes the config key better
|
|
'public' => 'public-%tenant_id%',
|
|
],
|
|
|
|
/**
|
|
* Should storage_path() be suffixed.
|
|
*
|
|
* Note: Disabling this will likely break local disk tenancy. Only disable this if you're using an external file storage service like S3.
|
|
*
|
|
* For the vast majority of applications, this feature should be enabled. But in some
|
|
* edge cases, it can cause issues (like using Passport with Vapor - see #196), so
|
|
* you may want to disable this if you are experiencing these edge case issues.
|
|
*/
|
|
'suffix_storage_path' => true,
|
|
|
|
/**
|
|
* By default, asset() calls are made multi-tenant too. You can use global_asset() and mix()
|
|
* for global, non-tenant-specific assets. However, you might have some issues when using
|
|
* packages that use asset() calls inside the tenant app. To avoid such issues, you can
|
|
* disable asset() helper tenancy and explicitly use tenant_asset() calls in places
|
|
* where you want to use tenant-specific assets (product images, avatars, etc).
|
|
*/
|
|
'asset_helper_tenancy' => true,
|
|
],
|
|
|
|
/**
|
|
* Redis tenancy config. Used by RedisTenancyBoostrapper.
|
|
*
|
|
* Note: You need phpredis to use Redis tenancy.
|
|
*
|
|
* Note: You don't need to use this if you're using Redis only for cache.
|
|
* Redis tenancy is only relevant if you're making direct Redis calls,
|
|
* either using the Redis facade or by injecting it as a dependency.
|
|
*/
|
|
'redis' => [
|
|
'prefix_base' => 'tenant', // Each key in Redis will be prepended by this prefix_base, followed by the tenant id.
|
|
'prefixed_connections' => [ // Redis connections whose keys are prefixed, to separate one tenant's keys from another.
|
|
// 'default',
|
|
],
|
|
],
|
|
|
|
/**
|
|
* Features are classes that provide additional functionality
|
|
* not needed for tenancy to be bootstrapped. They are run
|
|
* regardless of whether tenancy has been initialized.
|
|
*
|
|
* See the documentation page for each class to
|
|
* understand which ones you want to enable.
|
|
*/
|
|
'features' => [
|
|
// Stancl\Tenancy\Features\UserImpersonation::class,
|
|
// Stancl\Tenancy\Features\TelescopeTags::class,
|
|
// Stancl\Tenancy\Features\UniversalRoutes::class,
|
|
// Stancl\Tenancy\Features\TenantConfig::class, // https://tenancyforlaravel.com/docs/v3/features/tenant-config
|
|
// Stancl\Tenancy\Features\CrossDomainRedirect::class, // https://tenancyforlaravel.com/docs/v3/features/cross-domain-redirect
|
|
],
|
|
|
|
/**
|
|
* Should tenancy routes be registered.
|
|
*
|
|
* Tenancy routes include tenant asset routes. By default, this route is
|
|
* enabled. But it may be useful to disable them if you use external
|
|
* storage (e.g. S3 / Dropbox) or have a custom asset controller.
|
|
*/
|
|
'routes' => true,
|
|
|
|
/**
|
|
* Parameters used by the tenants:migrate command.
|
|
*/
|
|
'migration_parameters' => [
|
|
'--force' => true, // This needs to be true to run migrations in production.
|
|
'--path' => [database_path('migrations/tenant')],
|
|
'--schema-path' => database_path('schema/tenant-schema.dump'),
|
|
'--realpath' => true,
|
|
],
|
|
|
|
/**
|
|
* Parameters used by the tenants:seed command.
|
|
*/
|
|
'seeder_parameters' => [
|
|
'--class' => 'DatabaseSeeder', // root seeder class
|
|
// '--force' => true,
|
|
],
|
|
|
|
/**
|
|
* Single-database tenancy config.
|
|
*/
|
|
'single_db' => [
|
|
/** The name of the column used by models with the BelongsToTenant trait. */
|
|
'tenant_id_column' => 'tenant_id',
|
|
],
|
|
];
|