kuvia/database/migrations/2021_01_20_232501_fast_access_log.php

58 lines
1.5 KiB
PHP
Raw Normal View History

2021-01-21 00:13:41 +00:00
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class FastAccessLog extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table("access", function(Blueprint $table) {
$table->unsignedBigInteger("gallery")->nullable()->change();
2021-01-21 00:31:02 +00:00
//$table->unsignedBigInteger("tenant")->nullable()->change();
2021-01-21 00:13:41 +00:00
});
Schema::table("traffic", function(Blueprint $table) {
$table->unsignedBigInteger("gallery")->nullable()->change();
});
2021-01-21 00:31:02 +00:00
Schema::table("images", function (Blueprint $table) {
$table->unsignedBigInteger("tenant");
});
$images = \App\Models\Image::query()->get();
foreach ($images as $image) {
if(is_null($image->gallery)) {
$image->tenant = 1;
$image->saveOrFail();
} else {
$gallery = \App\Models\Gallery::query()->where("id", "=", $image->gallery)->firstOrFail();
$image->tenant = $gallery->tenant;
$image->saveOrFail();
}
}
Schema::table("images", function (Blueprint $table) {
$table->foreign('tenant')->references('id')->on('tenants');
});
2021-01-21 00:13:41 +00:00
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}