Rewrite the entire scheduled maintenance implementation

This commit is contained in:
James Brooks
2016-10-30 20:54:12 +00:00
parent a2cded299d
commit ebed68a7d8
57 changed files with 1989 additions and 512 deletions

View File

@@ -16,6 +16,7 @@ use CachetHQ\Cachet\Models\IncidentTemplate;
use CachetHQ\Cachet\Models\IncidentUpdate;
use CachetHQ\Cachet\Models\Metric;
use CachetHQ\Cachet\Models\MetricPoint;
use CachetHQ\Cachet\Models\Schedule;
use CachetHQ\Cachet\Models\Setting;
use CachetHQ\Cachet\Models\Subscriber;
use CachetHQ\Cachet\Models\Subscription;
@@ -89,6 +90,15 @@ $factory->define(MetricPoint::class, function ($faker) {
];
});
$factory->define(Schedule::class, function ($faker) {
return [
'name' => $faker->sentence(),
'message' => $faker->paragraph(),
'status' => Schedule::UPCOMING,
'scheduled_at' => Carbon::now()->addDays(7),
];
});
$factory->define(Setting::class, function ($faker) {
return [
'name' => 'app_name',

View File

@@ -28,6 +28,7 @@ class CreateSchedulesTable extends Migration
$table->longText('message')->nullable()->default(null);
$table->tinyInteger('status')->unsigned()->default(0);
$table->timestamp('scheduled_at');
$table->timestamp('completed_at')->nullable()->default(null);
$table->timestamps();
});
}

View File

@@ -0,0 +1,47 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class AlterTableIncidentsRemoveScheduledColumns extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// We need a better way of handling data migrations...
DB::update('INSERT INTO schedules (name, message, scheduled_at, created_at, updated_at) SELECT name, message, scheduled_at, created_at, updated_at FROM incidents WHERE scheduled_at IS NOT NULL');
DB::table('incidents')->whereNotNull('scheduled_at')->delete();
Schema::table('incidents', function (Blueprint $table) {
$table->dropColumn('scheduled_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('incidents', function (Blueprint $table) {
$table->timestamp('scheduled_at')->after('user_id')->nullable()->default(null);
});
}
}