mirror of
https://github.com/stancl/tenancy-docs.git
synced 2025-12-15 03:34:03 +00:00
Added migration file sample
This commit is contained in:
parent
ecfbaf6a12
commit
3554f7d34b
1 changed files with 52 additions and 20 deletions
|
|
@ -41,35 +41,67 @@ 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();
|
||||
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->unsignedBigInteger('id')->nullable();
|
||||
});
|
||||
Schema::table('domains', function (Blueprint $table) {
|
||||
$table->increments('id')->before('domain');
|
||||
$table->unique('domain');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
$counter = 1;
|
||||
foreach ($domains as $domain) {
|
||||
DB::table('domains')
|
||||
->where('domain', $domain->domain)
|
||||
->update(['id' => $counter]);
|
||||
$counter += 1;
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
});
|
||||
```
|
||||
|
||||
- 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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue