| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- use App\Station;
- use App\StationType;
- use Illuminate\Database\Migrations\Migration;
- use Illuminate\Database\Schema\Blueprint;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Schema;
- class CreateStationsTable extends Migration
- {
- /**
- * Run the migrations.
- *
- * @return void
- */
- public function up()
- {
- Schema::create('stations', function (Blueprint $table) {
- $table->id();
- $table->integer('parent_id')->index()->nullable();
- $table->string('name')->index()->nullable();
- $table->string('code')->unique()->nullable()->comment('机器编码');
- $table->integer('station_type_id')->index();
- $table->integer('sequence')->index()->nullable();
- $table->timestamps();
- });
- $db1 = DB::selectOne(DB::raw("SELECT * FROM station_types where name = ?"),["料箱出货口"]);
- $db2 = DB::selectOne(DB::raw("SELECT * FROM station_types where name = ?"),["料箱监视器01"]);
- if ($db1 && $db2){
- DB::insert(DB::raw("INSERT INTO stations(name,code,station_type_id,parent_id,sequence) VALUES (?,?,?,?,?)"),[
- 'U型线入货口01','BIN-OUT1',$db1->id,$db2->id,1,
- ]);
- }
- }
- /**
- * Reverse the migrations.
- *
- * @return void
- */
- public function down()
- {
- Schema::dropIfExists('stations');
- }
- }
|