Merge branch 'master' of github.com:stancl/tenancy-docs

This commit is contained in:
Samuel Štancl 2020-06-25 10:42:35 +02:00
commit d4eae62096
2 changed files with 62 additions and 23 deletions

View file

@ -8,13 +8,20 @@ section: content
Make sure your [queues]({{ $page->link('queues') }}) are configured correctly before using this.
You may add the current tenant's id to your job tags:
## Tags
You may add the current tenant's id to your job tags by defining a `tags` method on the class:
```php
/**
* Get the tags that should be assigned to the job.
*
* @return array
*/
public function tags()
{
return [
'tenant' => tenant('id'),
'tenant:' . tenant('id'),
];
}
```

View file

@ -41,38 +41,70 @@ That said, automatic tenancy will still work the same way.
```
- Add an `id` autoincrement column to `domains` table and retroactively generate the ids
(Note: You may want to make this part of a migration)
- Create migration file with `php artisan make:migration upgrade_tenancy_package`
```php
use Illuminate\Support\Facades\Schema;
<?php
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
$domains = DB::table('domains')->get();
Schema::table('domains', function (Blueprint $table) {
$table->unsignedBigInteger('id')->nullable();
});
$counter = 1;
foreach ($domains as $domain) {
DB::table('domains')
->where('domain', $domain->domain)
->update(['id' => $counter]);
$counter += 1;
}
class UpgradeTenancyPackage extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('domains', function (Blueprint $table) {
$table->dropPrimary();
});
Schema::table('domains', function (Blueprint $table) {
$table->primary('id'); // todo: here we want to make it autoincrement, not just primary
$table->increments('id')->first();
$table->unique('domain');
$table->timestamps();
});
Schema::table('tenants', function (Blueprint $table) {
$table->json('data')->nullable()->change();
$table->timestamps();
});
DB::table('domains')->update([
'created_at' => now(),
'updated_at' => now()
]);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('domains', function (Blueprint $table) {
$table->dropColumn('id');
$table->dropUnique(['domain']);
$table->dropTimestamps();
$table->primary('domain');
});
Schema::table('tenants', function (Blueprint $table) {
$table->json('data')->nullable(false)->change();
$table->dropTimestamps();
});
}
}
```
- Replace your Http Kernel with a stock version (copy it from laravel/laravel: [https://github.com/laravel/laravel/blob/master/app/Http/Kernel.php](https://github.com/laravel/laravel/blob/master/app/Http/Kernel.php)) and add back in any changes you made. The package now doesn't necessitate any Kernel changes, so remove all of the 2.x ones.
- Delete config, publish it & the new files using `php artisan tenancy:install`
- Delete config, publish it & the new files using `php artisan tenancy:install`. Register the new provider (see instructions on the [Installation]({{ $page->link('installation') }}) page)
- Create Tenant model, as instructed on the [Tenants]({{ $page->link('tenants') }}) page
- Update routes to use the correct middleware, see the [Routes]({{ $page->link('routes') }}) page