2019_01_19_015139_add_col_users_table.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. use Illuminate\Support\Facades\Schema;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Database\Migrations\Migration;
  5. class AddColUsersTable extends Migration
  6. {
  7. /**
  8. * Run the migrations.
  9. *
  10. * @return void
  11. */
  12. public function up()
  13. {
  14. if(!Schema::hasColumn('users','wechat_id')){
  15. Schema::table('users', function (Blueprint $table) {
  16. $table->string('wechat_id')->after('id')->nullable()->comment('微信id');
  17. });
  18. }
  19. if(!Schema::hasColumn('users','mobile')){
  20. Schema::table('users', function (Blueprint $table) {
  21. $table->char('mobile',11)->after('email')->index()->comment('手机');
  22. });
  23. }
  24. if(!Schema::hasColumn('users','nickname')){
  25. Schema::table('users', function (Blueprint $table) {
  26. $table->string('nickname')->after('name')->nullable()->comment('昵称');
  27. });
  28. }
  29. if(!Schema::hasColumn('users','avatar')){
  30. Schema::table('users', function (Blueprint $table) {
  31. $table->string('avatar')->after('mobile')->nullable()->comment('头像');
  32. });
  33. }
  34. if(!Schema::hasColumn('users','school_id')){
  35. Schema::table('users', function (Blueprint $table) {
  36. $table->string('school_id')->after('avatar')->nullable()->comment('头像');
  37. });
  38. }
  39. if(!Schema::hasColumn('sclass_id','sclass')){
  40. Schema::table('users', function (Blueprint $table) {
  41. $table->integer('sclass_id')->after('school_id')->nullable()->comment('班级');
  42. });
  43. }
  44. if(!Schema::hasColumn('grade_id','grade')){
  45. Schema::table('users', function (Blueprint $table) {
  46. $table->integer('grade_id')->after('class_id')->nullable()->comment('班级');
  47. });
  48. }
  49. }
  50. /**
  51. * Reverse the migrations.
  52. *
  53. * @return void
  54. */
  55. public function down()
  56. {
  57. if(Schema::hasColumn('users','mobile')){
  58. Schema::table('users', function (Blueprint $table) {
  59. $table->dropColumn('mobile');
  60. });
  61. }
  62. if(Schema::hasColumn('users','nickname')){
  63. Schema::table('users', function (Blueprint $table) {
  64. $table->dropColumn('nickname');
  65. });
  66. }
  67. if(Schema::hasColumn('users','avatar')){
  68. Schema::table('users', function (Blueprint $table) {
  69. $table->dropColumn('avatar');
  70. });
  71. }
  72. }
  73. }