Skip to content

Commit 2de781a

Browse files
committed
Create UpdateUsersTable.php
1 parent fb1b721 commit 2de781a

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
* UserFrosting (http://www.userfrosting.com)
5+
*
6+
* @link https://github.com/userfrosting/UserFrosting
7+
* @copyright Copyright (c) 2019 Alexander Weissman
8+
* @license https://github.com/userfrosting/UserFrosting/blob/master/LICENSE.md (MIT License)
9+
*/
10+
11+
namespace UserFrosting\Sprinkle\Account\Database\Migrations\v430;
12+
13+
use Illuminate\Database\Schema\Blueprint;
14+
use UserFrosting\Sprinkle\Core\Database\Migration;
15+
16+
/**
17+
* Groups table migration
18+
* Changes `group_id` column properties to allow user to be created without a group.
19+
* Version 4.3.0.
20+
*
21+
* See https://laravel.com/docs/5.4/migrations#tables
22+
*
23+
* @author Amos Folz
24+
*/
25+
class UpdateUsersTable extends Migration
26+
{
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
public static $dependencies = [
31+
'\UserFrosting\Sprinkle\Account\Database\Migrations\v400\GroupsTable',
32+
'\UserFrosting\Sprinkle\Account\Database\Migrations\v400\UsersTable',
33+
'\UserFrosting\Sprinkle\Account\Database\Migrations\v420\AddingForeignKeys',
34+
];
35+
36+
/**
37+
* {@inheritdoc}
38+
*/
39+
public function up()
40+
{
41+
if ($this->schema->hasTable('users')) {
42+
$this->schema->table('users', function (Blueprint $table) {
43+
$table->dropIndex(['group_id']);
44+
$table->unsignedInteger('group_id')->comment('The id of the user group.')->nullable()->change();
45+
});
46+
}
47+
}
48+
49+
/**
50+
* {@inheritdoc}
51+
*/
52+
public function down()
53+
{
54+
$this->schema->table('users', function (Blueprint $table) {
55+
$table->unsignedInteger('group_id')->default(1)->comment('The id of the user group.')->nullable(false)->change();
56+
});
57+
}
58+
}

0 commit comments

Comments
 (0)