2020_11_30_140958_create_stations_table.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. use App\Station;
  3. use App\StationType;
  4. use Illuminate\Database\Migrations\Migration;
  5. use Illuminate\Database\Schema\Blueprint;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Support\Facades\Schema;
  8. class CreateStationsTable extends Migration
  9. {
  10. /**
  11. * Run the migrations.
  12. *
  13. * @return void
  14. */
  15. public function up()
  16. {
  17. Schema::create('stations', function (Blueprint $table) {
  18. $table->id();
  19. $table->integer('parent_id')->index()->nullable();
  20. $table->string('name')->index()->nullable();
  21. $table->string('code')->unique()->nullable()->comment('机器编码');
  22. $table->integer('station_type_id')->index();
  23. $table->integer('sequence')->index()->nullable();
  24. $table->timestamps();
  25. });
  26. $db1 = DB::selectOne(DB::raw("SELECT * FROM station_types where name = ?"),["料箱出货口"]);
  27. $db2 = DB::selectOne(DB::raw("SELECT * FROM station_types where name = ?"),["料箱监视器01"]);
  28. if ($db1 && $db2){
  29. DB::insert(DB::raw("INSERT INTO stations(name,code,station_type_id,parent_id,sequence) VALUES (?,?,?,?,?)"),[
  30. 'U型线入货口01','BIN-OUT1',$db1->id,$db2->id,1,
  31. ]);
  32. }
  33. }
  34. /**
  35. * Reverse the migrations.
  36. *
  37. * @return void
  38. */
  39. public function down()
  40. {
  41. Schema::dropIfExists('stations');
  42. }
  43. }