Make scheduled statuses work under PgSQL and existing installations

This commit is contained in:
James Brooks
2015-02-28 21:50:50 +00:00
parent 92c43318a8
commit 6bf5ad2328
4 changed files with 42 additions and 7 deletions

View File

@@ -20,7 +20,6 @@ class CreateIncidentsTable extends Migration
$table->integer('status');
$table->longText('message');
$table->integer('user_id');
$table->timestamp('scheduled_at');
$table->timestamps();
$table->softDeletes();

View File

@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
class UpdateIncidentsAddScheduledAt extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('incidents', function(Blueprint $table)
{
$table->timestamp('scheduled_at')->after('user_id')->nullable()->default(null);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('incidents', function(Blueprint $table)
{
$table->dropColumn('scheduled_at');
});
}
}

View File

@@ -22,7 +22,7 @@ class IncidentTableSeeder extends Seeder
"status" => 4,
"component_id" => 0,
"user_id" => 1,
"scheduled_at" => "0000-00-00 00:00:00",
"scheduled_at" => null,
],
[
"name" => "Monitoring the fix",
@@ -30,7 +30,7 @@ class IncidentTableSeeder extends Seeder
"status" => 3,
"component_id" => 0,
"user_id" => 1,
"scheduled_at" => "0000-00-00 00:00:00",
"scheduled_at" => null,
],
[
"name" => "Update",
@@ -38,14 +38,14 @@ class IncidentTableSeeder extends Seeder
"status" => 2,
"component_id" => 0,
"user_id" => 1,
"scheduled_at" => "0000-00-00 00:00:00",
"scheduled_at" => null,
],
[
"name" => "Test Incident",
"message" => "Something went wrong, oh noes.",
"component_id" => 0,
"user_id" => 1,
"scheduled_at" => "0000-00-00 00:00:00",
"scheduled_at" => null,
],
];

View File

@@ -81,7 +81,7 @@ class Incident extends Model implements TransformableInterface, PresenterInterfa
public function scopeNotScheduled($query)
{
return $query->where(function ($query) {
return $query->where('scheduled_at', '0000-00-00 00:00:00')->orWhereRaw('scheduled_at <= NOW()');
return $query->whereNull('scheduled_at')->orWhereRaw('scheduled_at <= NOW()');
});
}
@@ -124,7 +124,7 @@ class Incident extends Model implements TransformableInterface, PresenterInterfa
*/
public function getIsScheduledAttribute()
{
return $this->getOriginal('scheduled_at') != '0000-00-00 00:00:00';
return $this->getOriginal('scheduled_at');
}
/**