Files
speedtest-tracker/database/migrations/2022_08_31_193643_create_speedtests_table.php
T
Alex Justesen eb5341a3f1 initial commit
2022-09-11 09:40:09 -04:00

47 lines
1.1 KiB
PHP

<?php
use App\Models\Speedtest;
use Cron\CronExpression;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('speedtests', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('schedule')->nullable();
$table->integer('ookla_server_id')->nullable();
$table->timestamp('next_run_at');
$table->timestamps();
});
$expression = '*/10 * * * *';
$cron = new CronExpression($expression);
Speedtest::create([
'name' => 'default',
'schedule' => $expression,
'next_run_at' => $cron->getNextRunDate()->format('Y-m-d H:i'),
]);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('speedtests');
}
};