@@ -12,19 +12,24 @@ class LaratrustUpgradeTables extends Migration
12
12
*/
13
13
public function up()
14
14
{
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();
19
15
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 ' ] } } '] );
24
20
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']);
26
23
});
27
24
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
+ });
28
33
}
29
34
30
35
/**
@@ -34,6 +39,22 @@ public function up()
34
39
*/
35
40
public function down()
36
41
{
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
+ });
38
59
}
39
60
}
0 commit comments