Skip to content
Permalink
Browse files

Implement upgrade scripts, in order to keep migrations clean for unit…

… tests
  • Loading branch information...
mikebronner committed Jun 20, 2019
1 parent 9b16f22 commit a574f113b0bfdf3544ea1a9537681fb1222f2a3f
@@ -70,14 +70,25 @@ composer require genealabs/laravel-governor
## Upgrading
The following upgrade guides should help navigate updates with breaking changes.

### From 0.11.5+ to 0.12 [Breaking]
The role_user pivot table has replaced the composite key with a primary key, as Laravel does not fully support composite keys. Run:
```sh
php artisan db:seed --class="LaravelGovernorUpgradeTo0120"
```

### From 0.11 to 0.11.5 [Breaking]
The primary keys of the package's tables have been renamed. (This should have been a minor version change, instead of a patch, as this was a breaking change.) Run:
```sh
php artisan db:seed --class="LaravelGovernorUpgradeTo0115"
```

### From 0.10 to 0.11 [Breaking]
The following traits have changed:
- `Governable` has been renamed to `Governing`.
- `Governed` has been renamed to `Governable`.
- the `governor_created_by` has been renamed to `governor_owned_by`. Run
migrations to update your tables.
- the `governor_created_by` has been renamed to `governor_owned_by`. Run migrations to update your tables.
```sh
php artisan migrate --path="vendor/genealabs/laravel-governor/database/migrations"
php artisan db:seed --class="LaravelGovernorUpgradeTo0110"
```
- replace any reference in your app from `governor_created_by` to
`governor_owned_by`.
@@ -16,11 +16,12 @@ public function up()
{
Schema::create('governor_role_user', function (Blueprint $table) {
$user = app()->make(config('genealabs-laravel-governor.models.auth'));
$table->string('role_name')
->index();
$table->bigInteger('user_id')
->unsigned()
->index();
$table->bigIncrements("id");
$table->string('role_name');
$table->unsignedBigInteger('user_id');
$table->timestamps();
$table->unique(["role_name", "user_id"]);
$table->foreign('role_name')
->references('name')
->on('governor_roles')
@@ -16,10 +16,13 @@ public function up()
{
Schema::create('governor_permissions', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('role_name');
$table->string('role_name')
->nullable();
$table->string('entity_name');
$table->string('action_name');
$table->string('ownership_name');
$table->unsignedBigInteger("team_id")
->nullable();
$table->timestamps();
$table->unique(['role_name', 'entity_name', 'action_name', 'ownership_name']);
@@ -43,6 +46,11 @@ public function up()
->on('governor_ownerships')
->onDelete('CASCADE')
->onUpdate('CASCADE');
$table->foreign('team_id')
->references('id')
->on('governor_teams')
->onDelete('SET NULL')
->onUpdate('CASCADE');
});
}

This file was deleted.

This file was deleted.

@@ -1,19 +1,12 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Seeder;
use Illuminate\Support\Collection;
class RenameGovernorCreatedByFields extends Migration
class LaravelGovernorUpgradeTo0110 extends Seeder
{
public function __construct()
{
if (app()->bound("Hyn\Tenancy\Environment")) {
$this->connection = config("tenancy.tenant-connection-name");
}
}
public function up()
public function run()
{
$this
->getTableNames()
@@ -42,19 +35,6 @@ public function up()
});
}
public function down()
{
$this
->getTableNames()
->each(function ($tableName) {
if (Schema::hasColumn($tableName, 'governor_owned_by')) {
Schema::table($tableName, function (Blueprint $table) {
$table->renameColumn("governor_owned_by", "governor_created_by");
});
}
});
}
protected function getTableNames() : Collection
{
return collect(app("db")
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Seeder;
use GeneaLabs\LaravelOptimizedPostgres\Schema;
class LaravelGovernorUpgradeTo0115 extends Seeder
{
public function run()
{
Schema::table("governor_permissions", function (Blueprint $table) {
$table->dropIndexIfExists("governor_permissions_role_name_entity_name_action_name_ownership_name_unique");
});
Schema::table("governor_permissions", function (Blueprint $table) {
$table->string("role_name")
->nullable()
->change();
if (! Schema::hasColumn("governor_permissions", "team_id")) {
$table->unsignedBigInteger("team_id")
->nullable();
$table->unique([
"team_id",
'role_name',
'entity_name',
'action_name',
'ownership_name',
]);
}
});
}
}
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Seeder;
class LaravelGovernorUpgradeTo0120 extends Seeder
{
public function run()
{
Schema::table('governor_role_user', function (Blueprint $table) {
if (! Schema::hasColumn("governor_role_user", "id")) {
$table->bigIncrements("id");
}
$table->string('role_name')
->change();
$table->unsignedBigInteger('user_id')
->change();
if (! Schema::hasColumn("governor_role_user", "created_at")) {
$table->timestamps();
}
// $table->dropIndex("role_name");
$table->dropIndexIfExists("governor_role_user_role_name_index");
// $table->dropIndex("user_id");
$table->dropIndexIfExists("governor_role_user_user_id_index");
});
}
}
Binary file not shown.

0 comments on commit a574f11

Please sign in to comment.
You can’t perform that action at this time.