EventConfig: Use text column instead of json if not supported

This commit is contained in:
Igor Scheller 2018-10-03 18:47:25 +02:00 committed by msquare
parent 7f61dc95be
commit 689ad7d5d5
1 changed files with 18 additions and 5 deletions

View File

@ -5,6 +5,7 @@ namespace Engelsystem\Migrations;
use Carbon\Carbon; use Carbon\Carbon;
use Engelsystem\Database\Migration\Migration; use Engelsystem\Database\Migration\Migration;
use Engelsystem\Models\EventConfig; use Engelsystem\Models\EventConfig;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
class CreateEventConfigTable extends Migration class CreateEventConfigTable extends Migration
@ -21,11 +22,23 @@ class CreateEventConfigTable extends Migration
*/ */
public function up() public function up()
{ {
$this->schema->create('event_config', function (Blueprint $table) { foreach (['json', 'text'] as $type) {
$table->string('name')->index()->unique(); try {
$table->json('value'); $this->schema->create('event_config', function (Blueprint $table) use ($type) {
$table->timestamps(); $table->string('name')->index()->unique();
}); $table->{$type}('value');
$table->timestamps();
});
} catch (QueryException $e) {
if ($type != 'json') {
throw $e;
}
continue;
}
break;
}
if ($this->schema->hasTable('EventConfig')) { if ($this->schema->hasTable('EventConfig')) {
$config = $this->schema->getConnection() $config = $this->schema->getConnection()