Change DB tables (remove temperature) (add sensors and readings Models Controllers and migrations) (and respect reallationships)
This commit is contained in:
@@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateTemperaturesTable extends Migration
|
||||
class CreateSensorsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
@@ -13,13 +13,15 @@ class CreateTemperaturesTable extends Migration
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('temperatures', function (Blueprint $table) {
|
||||
Schema::create('sensors', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->float('temperature', 2, 2);
|
||||
$table->boolean('sensor_status');
|
||||
$table->foreignId('user_id');
|
||||
$table->boolean('status');
|
||||
$table->float('longitude', 8, 6);
|
||||
$table->float('latitude', 8, 6);
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -30,6 +32,6 @@ class CreateTemperaturesTable extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('temperatures');
|
||||
Schema::dropIfExists('sensors');
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateReadingsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('readings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('sensor_id');
|
||||
$table->boolean('type');
|
||||
$table->float('value', 2, 2);
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('sensor_id')->references('id')->on('sensors');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('readings');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user