Skip to content

Commit aef2d31

Browse files
committed
Updates Docs and started working in the upgrade migration
1 parent 05edc72 commit aef2d31

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

docs/upgrade.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ In order to upgrade from Laratrust 3.1 to 3.2 you have to follow these steps:
2525

2626
6. Run ``php artisan migrate`` to apply the migration created in the previous step.
2727

28+
7. Delete the ``LaratrustSeeder.php`` file and run ``php artisan laratrust:seeder``.
29+
30+
8. Run ``composer dump-autoload``.
31+
2832
Now you can use the 3.2 version without any problem.

src/views/generators/upgrade-migration.blade.php

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,24 @@ class LaratrustUpgradeTables extends Migration
1212
*/
1313
public function up()
1414
{
15-
// Create table for associating permissions to users (Many-to-Many)
16-
Schema::create('{{ $laratrust['permission_user_table'] }}', function (Blueprint $table) {
17-
$table->integer('{{ $laratrust['permission_foreign_key'] }}')->unsigned();
18-
$table->integer('{{ $laratrust['user_foreign_key'] }}')->unsigned();
1915

20-
$table->foreign('{{ $laratrust['permission_foreign_key'] }}')->references('id')->on('{{ $laratrust['permissions_table'] }}')
21-
->onUpdate('cascade')->onDelete('cascade');
22-
$table->foreign('{{ $laratrust['user_foreign_key'] }}')->references('{{ $user->getKeyName() }}')->on('{{ $user->getTable() }}')
23-
->onUpdate('cascade')->onDelete('cascade');
16+
Schema::table('{{ $laratrust['role_user_table'] }}', function (Blueprint $table) {
17+
// Drop user foreign key and primary with role_id
18+
$table->dropForeign('{{ $laratrust['role_user_table'] }}_{{ $laratrust['user_foreign_key'] }}_foreign');
19+
$table->dropPrimary(['{{ $laratrust['user_foreign_key'] }}', '{{ $laratrust['role_foreign_key'] }}']);
2420

25-
$table->primary(['{{ $laratrust['permission_foreign_key'] }}', '{{ $laratrust['user_foreign_key'] }}']);
21+
$table->string('user_type');
22+
$table->primary(['{{ $laratrust['user_foreign_key'] }}', '{{ $laratrust['role_foreign_key'] }}', 'user_type']);
2623
});
2724

25+
Schema::table('{{ $laratrust['permission_user_table'] }}', function (Blueprint $table) {
26+
// Drop user foreign key and primary with permission_id
27+
$table->dropForeign('{{ $laratrust['permission_user_table'] }}_{{ $laratrust['user_foreign_key'] }}_foreign');
28+
$table->dropPrimary(['{{ $laratrust['user_foreign_key'] }}', '{{ $laratrust['permission_foreign_key'] }}']);
29+
30+
$table->string('user_type');
31+
$table->primary(['{{ $laratrust['user_foreign_key'] }}', '{{ $laratrust['permission_foreign_key'] }}', 'user_type']);
32+
});
2833
}
2934

3035
/**
@@ -34,6 +39,22 @@ public function up()
3439
*/
3540
public function down()
3641
{
37-
Schema::dropIfExists('{{ $laratrust['permission_user_table'] }}');
42+
Schema::table('{{ $laratrust['role_user_table'] }}', function (Blueprint $table) {
43+
$table->dropPrimary(['{{ $laratrust['user_foreign_key'] }}', '{{ $laratrust['role_foreign_key'] }}', 'user_type']);
44+
$table->dropColumn('user_type');
45+
46+
$table->foreign('{{ $laratrust['user_foreign_key'] }}')->references('{{ $user->getKeyName() }}')->on('{{ $user->getTable() }}')
47+
->onUpdate('cascade')->onDelete('cascade');
48+
$table->primary(['{{ $laratrust['user_foreign_key'] }}', '{{ $laratrust['role_foreign_key'] }}']);
49+
});
50+
51+
Schema::table('{{ $laratrust['permission_user_table'] }}', function (Blueprint $table) {
52+
$table->dropPrimary(['{{ $laratrust['user_foreign_key'] }}', '{{ $laratrust['permission_foreign_key'] }}', 'user_type']);
53+
$table->dropColumn('user_type');
54+
55+
$table->foreign('{{ $laratrust['user_foreign_key'] }}')->references('{{ $user->getKeyName() }}')->on('{{ $user->getTable() }}')
56+
->onUpdate('cascade')->onDelete('cascade');
57+
$table->primary(['{{ $laratrust['user_foreign_key'] }}', '{{ $laratrust['permission_foreign_key'] }}']);
58+
});
3859
}
3960
}

0 commit comments

Comments
 (0)