| @@ 6-110 (lines=105) @@ | ||
| 3 | use Illuminate\Database\Schema\Blueprint; |
|
| 4 | use Illuminate\Database\Migrations\Migration; |
|
| 5 | ||
| 6 | class InitializeCore extends Migration |
|
| 7 | { |
|
| 8 | /** |
|
| 9 | * Run the migrations. |
|
| 10 | * |
|
| 11 | * @return void |
|
| 12 | */ |
|
| 13 | public function up() |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * Delete previous permissions. |
|
| 17 | */ |
|
| 18 | DB::table('permissions')->whereIn('model', ['settings'])->delete(); |
|
| 19 | ||
| 20 | /** |
|
| 21 | * Insert the permissions related to this module. |
|
| 22 | */ |
|
| 23 | DB::table('permissions')->insert( |
|
| 24 | [ |
|
| 25 | /** |
|
| 26 | * Users model permissions. |
|
| 27 | */ |
|
| 28 | [ |
|
| 29 | 'name' => 'save', |
|
| 30 | 'model' => 'settings', |
|
| 31 | 'created_at' => \DB::raw('NOW()'), |
|
| 32 | 'updated_at' => \DB::raw('NOW()') |
|
| 33 | ], |
|
| 34 | [ |
|
| 35 | 'name' => 'find', |
|
| 36 | 'model' => 'settings', |
|
| 37 | 'created_at' => \DB::raw('NOW()'), |
|
| 38 | 'updated_at' => \DB::raw('NOW()') |
|
| 39 | ], |
|
| 40 | [ |
|
| 41 | 'name' => 'search', |
|
| 42 | 'model' => 'settings', |
|
| 43 | 'created_at' => \DB::raw('NOW()'), |
|
| 44 | 'updated_at' => \DB::raw('NOW()') |
|
| 45 | ], |
|
| 46 | [ |
|
| 47 | 'name' => 'list', |
|
| 48 | 'model' => 'settings', |
|
| 49 | 'created_at' => \DB::raw('NOW()'), |
|
| 50 | 'updated_at' => \DB::raw('NOW()') |
|
| 51 | ], |
|
| 52 | [ |
|
| 53 | 'name' => 'findby', |
|
| 54 | 'model' => 'settings', |
|
| 55 | 'created_at' => \DB::raw('NOW()'), |
|
| 56 | 'updated_at' => \DB::raw('NOW()') |
|
| 57 | ], |
|
| 58 | [ |
|
| 59 | 'name' => 'first', |
|
| 60 | 'model' => 'settings', |
|
| 61 | 'created_at' => \DB::raw('NOW()'), |
|
| 62 | 'updated_at' => \DB::raw('NOW()') |
|
| 63 | ], |
|
| 64 | [ |
|
| 65 | 'name' => 'paginate', |
|
| 66 | 'model' => 'settings', |
|
| 67 | 'created_at' => \DB::raw('NOW()'), |
|
| 68 | 'updated_at' => \DB::raw('NOW()') |
|
| 69 | ], |
|
| 70 | [ |
|
| 71 | 'name' => 'paginateby', |
|
| 72 | 'model' => 'settings', |
|
| 73 | 'created_at' => \DB::raw('NOW()'), |
|
| 74 | 'updated_at' => \DB::raw('NOW()') |
|
| 75 | ] |
|
| 76 | ] |
|
| 77 | ); |
|
| 78 | ||
| 79 | /** |
|
| 80 | * Assign the permissions to the admin group. |
|
| 81 | */ |
|
| 82 | $permissionIds = DB::table('permissions')->whereIn('model', ['settings'])->select('id')->lists('id'); |
|
| 83 | $adminGroupId = DB::table('groups')->where('name', 'Admin')->first()->id; |
|
| 84 | foreach ($permissionIds as $permissionId) |
|
| 85 | { |
|
| 86 | DB::table('groups_permissions')->insert( |
|
| 87 | [ |
|
| 88 | 'permission_id' => $permissionId, |
|
| 89 | 'group_id' => $adminGroupId, |
|
| 90 | 'created_at' => \DB::raw('NOW()'), |
|
| 91 | 'updated_at' => \DB::raw('NOW()') |
|
| 92 | ] |
|
| 93 | ); |
|
| 94 | } |
|
| 95 | } |
|
| 96 | ||
| 97 | /** |
|
| 98 | * Reverse the migrations. |
|
| 99 | * |
|
| 100 | * @return void |
|
| 101 | */ |
|
| 102 | public function down() |
|
| 103 | { |
|
| 104 | $adminGroupId = DB::table('groups')->where('name', 'Admin')->first()->id; |
|
| 105 | $adminUserId = DB::table('users')->where('email', '[email protected]')->first()->id; |
|
| 106 | ||
| 107 | DB::table('permissions')->whereIn('model', ['settings'])->delete(); |
|
| 108 | DB::table('users_groups')->where('user_id', $adminUserId)->where('group_id', $adminGroupId)->delete(); |
|
| 109 | } |
|
| 110 | } |
|
| @@ 6-110 (lines=105) @@ | ||
| 3 | use Illuminate\Database\Schema\Blueprint; |
|
| 4 | use Illuminate\Database\Migrations\Migration; |
|
| 5 | ||
| 6 | class Initialize extends Migration |
|
| 7 | { |
|
| 8 | /** |
|
| 9 | * Run the migrations. |
|
| 10 | * |
|
| 11 | * @return void |
|
| 12 | */ |
|
| 13 | public function up() |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * Delete previous permissions. |
|
| 17 | */ |
|
| 18 | DB::table('permissions')->whereIn('model', ['reports'])->delete(); |
|
| 19 | ||
| 20 | /** |
|
| 21 | * Insert the permissions related to this module. |
|
| 22 | */ |
|
| 23 | DB::table('permissions')->insert( |
|
| 24 | [ |
|
| 25 | /** |
|
| 26 | * Reporting model permissions. |
|
| 27 | */ |
|
| 28 | [ |
|
| 29 | 'name' => 'find', |
|
| 30 | 'model' => 'reports', |
|
| 31 | 'created_at' => \DB::raw('NOW()'), |
|
| 32 | 'updated_at' => \DB::raw('NOW()') |
|
| 33 | ], |
|
| 34 | [ |
|
| 35 | 'name' => 'search', |
|
| 36 | 'model' => 'reports', |
|
| 37 | 'created_at' => \DB::raw('NOW()'), |
|
| 38 | 'updated_at' => \DB::raw('NOW()') |
|
| 39 | ], |
|
| 40 | [ |
|
| 41 | 'name' => 'list', |
|
| 42 | 'model' => 'reports', |
|
| 43 | 'created_at' => \DB::raw('NOW()'), |
|
| 44 | 'updated_at' => \DB::raw('NOW()') |
|
| 45 | ], |
|
| 46 | [ |
|
| 47 | 'name' => 'findby', |
|
| 48 | 'model' => 'reports', |
|
| 49 | 'created_at' => \DB::raw('NOW()'), |
|
| 50 | 'updated_at' => \DB::raw('NOW()') |
|
| 51 | ], |
|
| 52 | [ |
|
| 53 | 'name' => 'first', |
|
| 54 | 'model' => 'reports', |
|
| 55 | 'created_at' => \DB::raw('NOW()'), |
|
| 56 | 'updated_at' => \DB::raw('NOW()') |
|
| 57 | ], |
|
| 58 | [ |
|
| 59 | 'name' => 'paginate', |
|
| 60 | 'model' => 'reports', |
|
| 61 | 'created_at' => \DB::raw('NOW()'), |
|
| 62 | 'updated_at' => \DB::raw('NOW()') |
|
| 63 | ], |
|
| 64 | [ |
|
| 65 | 'name' => 'paginateby', |
|
| 66 | 'model' => 'reports', |
|
| 67 | 'created_at' => \DB::raw('NOW()'), |
|
| 68 | 'updated_at' => \DB::raw('NOW()') |
|
| 69 | ], |
|
| 70 | [ |
|
| 71 | 'name' => 'admin_count', |
|
| 72 | 'model' => 'reports', |
|
| 73 | 'created_at' => \DB::raw('NOW()'), |
|
| 74 | 'updated_at' => \DB::raw('NOW()') |
|
| 75 | ] |
|
| 76 | ] |
|
| 77 | ); |
|
| 78 | ||
| 79 | /** |
|
| 80 | * Assign the permissions to the admin group. |
|
| 81 | */ |
|
| 82 | $permissionIds = DB::table('permissions')->whereIn('model', ['reports'])->select('id')->lists('id'); |
|
| 83 | $adminGroupId = DB::table('groups')->where('name', 'Admin')->first()->id; |
|
| 84 | foreach ($permissionIds as $permissionId) |
|
| 85 | { |
|
| 86 | DB::table('groups_permissions')->insert( |
|
| 87 | [ |
|
| 88 | 'permission_id' => $permissionId, |
|
| 89 | 'group_id' => $adminGroupId, |
|
| 90 | 'created_at' => \DB::raw('NOW()'), |
|
| 91 | 'updated_at' => \DB::raw('NOW()') |
|
| 92 | ] |
|
| 93 | ); |
|
| 94 | } |
|
| 95 | } |
|
| 96 | ||
| 97 | /** |
|
| 98 | * Reverse the migrations. |
|
| 99 | * |
|
| 100 | * @return void |
|
| 101 | */ |
|
| 102 | public function down() |
|
| 103 | { |
|
| 104 | $adminGroupId = DB::table('groups')->where('name', 'Admin')->first()->id; |
|
| 105 | $adminUserId = DB::table('users')->where('email', '[email protected]')->first()->id; |
|
| 106 | ||
| 107 | DB::table('permissions')->whereIn('model', ['reports'])->delete(); |
|
| 108 | DB::table('users_groups')->where('user_id', $adminUserId)->where('group_id', $adminGroupId)->delete(); |
|
| 109 | } |
|
| 110 | } |
|