Rebuild database migrations

This commit is contained in:
Deon George 2024-08-28 13:19:30 +10:00
parent daf44c7339
commit 2d04c8ccbb
23 changed files with 225 additions and 818 deletions

View File

@ -0,0 +1,56 @@
<?php
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('makes', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->string('name')->unique();
});
Schema::create('models', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->string('name')->nullable();
$table->bigInteger('make_id')->unsigned()->nullable();
$table->foreign('make_id')->references('id')->on('makes');
$table->unique(['name','make_id']);
});
Schema::create('software', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->string('name')->nullable();
$table->bigInteger('model_id')->unsigned()->nullable();
$table->foreign('model_id')->references('id')->on('models');
$table->unique(['name','model_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('software');
Schema::dropIfExists('models');
Schema::dropIfExists('makes');
}
};

View File

@ -0,0 +1,59 @@
<?php
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('photos', function(Blueprint $table)
{
$table->id();
$table->timestamps();
$table->softDeletes();
$table->smallInteger('subsectime')->nullable();
$table->string('filename',256)->index();
$table->string('file_signature')->index()->nullable();
$table->dateTimeTz('created')->nullable();
$table->dateTimeTz('created_manual')->nullable();
$table->string('signature',64)->index()->nullable();
$table->integer('height')->nullable();
$table->integer('width')->nullable();
$table->integer('orientation')->nullable();
$table->float('gps_lat',10)->nullable();
$table->float('gps_lon',10)->nullable();
$table->binary('thumbnail')->nullable();
$table->string('identifier')->nullable();
$table->boolean('duplicate')->default(FALSE)->nullable();
$table->boolean('flag')->default(FALSE)->nullable();
$table->boolean('scanned')->default(FALSE)->nullable();
$table->boolean('ignore_duplicate')->default(FALSE)->nullable();
$table->boolean('remove')->default(FALSE)->nullable();
$table->bigInteger('model_id')->unsigned()->nullable();
$table->foreign('model_id')->references('id')->on('models');
$table->bigInteger('software_id')->unsigned()->nullable();
$table->foreign('software_id')->references('id')->on('software');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('photos');
}
};

View File

@ -0,0 +1,65 @@
<?php
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('videos', function(Blueprint $table)
{
$table->id();
$table->timestamps();
$table->softDeletes();
$table->string('filename',256)->index();
$table->string('file_signature')->nullable();
$table->dateTimeTz('created')->nullable();
$table->dateTimeTz('created_manual')->nullable();
$table->string('signature',64)->index()->nullable();
$table->string('type',32)->nullable();
$table->string('codec',32)->nullable();
$table->integer('audiochannels')->nullable();
$table->string('channelmode',16)->nullable();
$table->float('samplerate',10,)->nullable();
$table->integer('height')->nullable();
$table->integer('width')->nullable();
$table->float('length')->nullable();
$table->integer('orientation')->nullable();
$table->float('gps_lat',10)->nullable();
$table->float('gps_lon',10)->nullable();
$table->float('gps_altitude',10)->nullable();
$table->string('identifier')->nullable();
$table->boolean('duplicate')->default(FALSE)->nullable();
$table->boolean('flag')->default(FALSE)->nullable();
$table->boolean('scanned')->default(FALSE)->nullable();
$table->boolean('ignore_duplicate')->default(FALSE)->nullable();
$table->boolean('remove')->default(FALSE)->nullable();
$table->bigInteger('model_id')->unsigned()->nullable();
$table->foreign('model_id')->references('id')->on('models');
$table->bigInteger('software_id')->unsigned()->nullable();
$table->foreign('software_id')->references('id')->on('software');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('videos');
}
};

View File

@ -2,9 +2,10 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePeopleTable extends Migration {
return new class extends Migration
{
/**
* Run the migrations.
*
@ -14,14 +15,14 @@ class CreatePeopleTable extends Migration {
{
Schema::create('people', function(Blueprint $table)
{
$table->integer('id', true);
$table->string('tag', 16)->unique('tag_UNIQUE');
$table->id();
$table->string('tag', 16)->unique();
$table->string('name', 64)->nullable();
$table->integer('date_birth')->nullable();
});
}
/**
* Reverse the migrations.
*
@ -31,5 +32,4 @@ class CreatePeopleTable extends Migration {
{
Schema::drop('people');
}
}
};

View File

@ -2,9 +2,10 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateTagsTable extends Migration {
return new class extends Migration
{
/**
* Run the migrations.
*
@ -14,13 +15,12 @@ class CreateTagsTable extends Migration {
{
Schema::create('tags', function(Blueprint $table)
{
$table->bigInteger('id', true);
$table->string('tag', 16)->unique('tag_UNIQUE');
$table->id();
$table->string('tag',16)->unique();
$table->string('description',45)->nullable();
});
}
/**
* Reverse the migrations.
*
@ -30,5 +30,4 @@ class CreateTagsTable extends Migration {
{
Schema::drop('tags');
}
}
};

View File

@ -1,48 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreatePhotoTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('photo', function(Blueprint $table)
{
$table->bigInteger('id', true);
$table->timestamps();
$table->integer('date_taken')->nullable();
$table->smallInteger('subsectime')->nullable();
$table->string('filename', 128);
$table->string('signature', 64)->nullable();
$table->string('make', 32)->nullable();
$table->string('model', 32)->nullable();
$table->integer('height')->nullable();
$table->integer('width')->nullable();
$table->integer('orientation')->nullable();
$table->float('gps_lat', 10, 0)->nullable();
$table->float('gps_lon', 10, 0)->nullable();
$table->binary('thumbnail', 65535)->nullable();
$table->boolean('duplicate')->nullable();
$table->boolean('remove')->nullable();
$table->boolean('flag')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('photo');
}
}

View File

@ -2,9 +2,10 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePhotoPeopleTable extends Migration {
return new class extends Migration
{
/**
* Run the migrations.
*
@ -12,17 +13,19 @@ class CreatePhotoPeopleTable extends Migration {
*/
public function up()
{
Schema::create('photo_people', function(Blueprint $table)
Schema::create('person_photo', function(Blueprint $table)
{
$table->bigInteger('id', true);
$table->id();
$table->timestamps();
$table->integer('people_id');
$table->bigInteger('photo_id')->index('fk_pp_ph_idx');
$table->unique(['people_id','photo_id'], 'UNIQUE');
$table->bigInteger('person_id');
$table->foreign('person_id')->references('id')->on('people');
$table->bigInteger('photo_id');
$table->foreign('photo_id')->references('id')->on('photos');
$table->unique(['person_id','photo_id']);
});
}
/**
* Reverse the migrations.
*
@ -30,7 +33,6 @@ class CreatePhotoPeopleTable extends Migration {
*/
public function down()
{
Schema::drop('photo_people');
}
Schema::drop('person_photo');
}
};

View File

@ -2,9 +2,10 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePhotoTagTable extends Migration {
return new class extends Migration
{
/**
* Run the migrations.
*
@ -14,15 +15,17 @@ class CreatePhotoTagTable extends Migration {
{
Schema::create('photo_tag', function(Blueprint $table)
{
$table->bigInteger('id', true);
$table->id();
$table->timestamps();
$table->bigInteger('tag_id');
$table->foreign('tag_id')->references('id')->on('tags');
$table->bigInteger('photo_id');
$table->bigInteger('tag_id')->index('pt_t_idx');
$table->unique(['photo_id','tag_id'], 'UNIQUE');
$table->foreign('photo_id')->references('id')->on('photos');
$table->unique(['photo_id','tag_id']);
});
}
/**
* Reverse the migrations.
*
@ -32,5 +35,4 @@ class CreatePhotoTagTable extends Migration {
{
Schema::drop('photo_tag');
}
}
};

View File

@ -1,37 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddForeignKeysToPhotoPeopleTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('photo_people', function(Blueprint $table)
{
$table->foreign('people_id', 'fk_pp_p')->references('id')->on('people')->onUpdate('NO ACTION')->onDelete('NO ACTION');
$table->foreign('photo_id', 'fk_pp_ph')->references('id')->on('photo')->onUpdate('NO ACTION')->onDelete('NO ACTION');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('photo_people', function(Blueprint $table)
{
$table->dropForeign('fk_pp_p');
$table->dropForeign('fk_pp_ph');
});
}
}

View File

@ -1,37 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddForeignKeysToPhotoTagTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('photo_tag', function(Blueprint $table)
{
$table->foreign('photo_id', 'fk_pt_p')->references('id')->on('photo')->onUpdate('NO ACTION')->onDelete('NO ACTION');
$table->foreign('tag_id', 'fk_pt_t')->references('id')->on('tags')->onUpdate('NO ACTION')->onDelete('NO ACTION');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('photo_tag', function(Blueprint $table)
{
$table->dropForeign('fk_pt_p');
$table->dropForeign('fk_pt_t');
});
}
}

View File

@ -1,37 +0,0 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class RenamePhotoPeople extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::rename('photo_people', 'person_photo');
Schema::table('person_photo', function (Blueprint $table) {
$table->dropForeign('person_photo_people_id_foreign');
$table->renameColumn('people_id', 'person_id');
$table->foreign('person_id')->references('id')->on('people');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('person_photo', function (Blueprint $table) {
$table->dropForeign('person_photo_person_id_foreign');
$table->renameColumn('person_id','people_id');
$table->foreign('people_id')->references('id')->on('people');
});
Schema::rename('person_photo','photo_people');
}
}

View File

@ -1,53 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateVideosTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('videos', function(Blueprint $table)
{
$table->bigInteger('id', true);
$table->timestamps();
$table->integer('date_created')->nullable();
$table->string('filename', 128);
$table->string('signature', 64)->nullable();
$table->string('make', 32)->nullable();
$table->string('model', 32)->nullable();
$table->string('type', 32)->nullable();
$table->string('codec', 32)->nullable();
$table->integer('audiochannels')->nullable();
$table->string('channelmode', 16)->nullable();
$table->float('samplerate', 10, 0)->nullable();
$table->integer('height')->nullable();
$table->integer('width')->nullable();
$table->float('length')->nullable();
$table->integer('orientation')->nullable();
$table->float('gps_lat', 10, 0)->nullable();
$table->float('gps_lon', 10, 0)->nullable();
$table->float('gps_altitude', 10, 0)->nullable();
$table->boolean('duplicate')->nullable();
$table->boolean('remove')->nullable();
$table->boolean('flag')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('videos');
}
}

View File

@ -14,11 +14,12 @@ class CreatePersonVideoTable extends Migration {
{
Schema::create('person_video', function(Blueprint $table)
{
$table->bigInteger('id', true);
$table->id();
$table->timestamps();
$table->integer('person_id');
$table->bigInteger('video_id')->index('fk_pp_ph_idx');
$table->unique(['person_id','video_id'], 'UNIQUE');
$table->bigInteger('video_id');
$table->unique(['person_id','video_id']);
});
}

View File

@ -14,11 +14,12 @@ class CreateTagVideoTable extends Migration {
{
Schema::create('tag_video', function(Blueprint $table)
{
$table->bigInteger('id', true);
$table->id();
$table->timestamps();
$table->bigInteger('video_id');
$table->bigInteger('tag_id')->index('pt_t_idx');
$table->unique(['video_id','tag_id'], 'UNIQUE');
$table->bigInteger('tag_id');
$table->unique(['video_id','tag_id']);
});
}

View File

@ -1,34 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class PhotosRenameFields extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('photo', function(Blueprint $table)
{
$table->renameColumn('date_taken', 'date_created');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('photo', function(Blueprint $table)
{
$table->renameColumn('date_created', 'date_taken');
});
}
}

View File

@ -1,51 +0,0 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class VideoAddScanned extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('photo', function (Blueprint $table) {
$table->boolean('scanned')->nullable();
$table->string('file_signature')->nullable();
$table->string('identifier')->nullable();
$table->string('software')->nullable();
});
Schema::table('videos', function (Blueprint $table) {
$table->boolean('scanned')->nullable();
$table->string('file_signature')->nullable();
$table->string('identifier')->nullable();
$table->string('software')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('photo', function (Blueprint $table) {
$table->dropColumn('scanned');
$table->dropColumn('file_signature');
$table->dropColumn('identifier');
$table->dropColumn('software');
});
Schema::table('videos', function (Blueprint $table) {
$table->dropColumn('scanned');
$table->dropColumn('file_signature');
$table->dropColumn('identifier');
$table->dropColumn('software');
});
}
}

View File

@ -1,54 +0,0 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class PhotoAddIndex extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('photo', function (Blueprint $table) {
$table->index(['signature']);
$table->index(['filename']);
$table->index(['remove']);
$table->index(['duplicate']);
$table->index(['date_created','subsectime','model','make']);
});
Schema::table('videos', function (Blueprint $table) {
$table->index(['signature']);
$table->index(['filename']);
$table->index(['remove']);
$table->index(['duplicate']);
$table->index(['date_created','model','make']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('photo', function (Blueprint $table) {
$table->dropIndex(['signature']);
$table->dropIndex(['filename']);
$table->dropIndex(['remove']);
$table->dropIndex(['duplicate']);
$table->dropIndex(['date_created','subsectime','model','make']);
});
Schema::table('videos', function (Blueprint $table) {
$table->dropIndex(['signature']);
$table->dropIndex(['filename']);
$table->dropIndex(['remove']);
$table->dropIndex(['duplicate']);
$table->dropIndex(['date_created','model','make']);
});
}
}

View File

@ -1,28 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class ChangeModelPhoto extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement('ALTER TABLE photo CHANGE model model varchar(128) DEFAULT null;');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::statement('ALTER TABLE photo CHANGE model model varchar(32) DEFAULT null;');
}
}

View File

@ -1,54 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class RevertIndexPhoto extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('photo', function (Blueprint $table) {
$table->dropIndex(['signature']);
$table->dropIndex(['filename']);
$table->dropIndex(['remove']);
$table->dropIndex(['duplicate']);
$table->dropIndex(['date_created','subsectime','model','make']);
});
Schema::table('videos', function (Blueprint $table) {
$table->dropIndex(['signature']);
$table->dropIndex(['filename']);
$table->dropIndex(['remove']);
$table->dropIndex(['duplicate']);
$table->dropIndex(['date_created','model','make']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('photo', function (Blueprint $table) {
$table->index(['signature']);
$table->index(['filename']);
$table->index(['remove']);
$table->index(['duplicate']);
$table->index(['date_created','subsectime','model','make']);
});
Schema::table('videos', function (Blueprint $table) {
$table->index(['signature']);
$table->index(['filename']);
$table->index(['remove']);
$table->index(['duplicate']);
$table->index(['date_created','model','make']);
});
}
}

View File

@ -1,127 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Models\{Photo,Make,Model,Software};
class CreateMakemodelTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('makes', function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
$table->string('name')->unique();
});
Schema::create('models', function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
$table->string('name')->nullable();
$table->bigInteger('make_id')->unsigned()->nullable();
$table->foreign('make_id')->references('id')->on('makes');
$table->unique(['name','make_id']);
});
Schema::create('software', function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
$table->string('name')->nullable();
$table->bigInteger('model_id')->unsigned()->nullable();
$table->foreign('model_id')->references('id')->on('models');
$table->unique(['name','model_id']);
});
Schema::table('photo', function (Blueprint $table) {
$table->bigInteger('software_id')->unsigned()->nullable();
$table->foreign('software_id')->references('id')->on('software');
});
$po = Photo::select(['make','model','software'])
->groupBy(['make','model','software']);
foreach ($po->get() as $o) {
if (! $o->make AND ! $o->model AND ! $o->software)
continue;
$ma = NULL;
dump(['make'=>$o->make,'model'=>$o->model,'software'=>$o->software]);
if ($o->make)
$ma = Make::firstOrCreate(['name'=>$o->make]);
$mo = Model::firstOrNew(['name'=>$o->model]);
if ($ma)
$mo->make_id = $ma->id;
$mo->save();
$so = Software::firstOrNew(['name'=>$o->software]);
if ($so)
$so->model_id = $mo->id;
$so->save();
foreach (Photo::where('make',$o->make)
->where('model',$o->model)
->where('software',$o->software)
->get() as $p) {
$p->software_id = $so->id;
$p->make = $p->model = $p->software = NULL;
$p->save();
}
}
Schema::table('photo', function (Blueprint $table) {
$table->dropColumn('make');
$table->dropColumn('model');
$table->dropColumn('software');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('photo', function (Blueprint $table) {
$table->string('make',32)->nullable();
$table->string('model',128)->nullable();
$table->string('software')->nullable();
});
foreach (Photo::whereNotNULL('software_id')->get() as $p)
{
$s = $p->software()->first();
$p->software = $s->name;
if ($s->model)
$p->model = $s->model->name;
if ($s->model->make)
$p->make = $s->model->make->name;
$p->software_id = NULL;
$p->save();
}
Schema::table('photo', function (Blueprint $table) {
$table->dropForeign(['software_id']);
$table->dropColumn('software_id');
});
Schema::dropIfExists('software');
Schema::dropIfExists('models');
Schema::dropIfExists('makes');
}
}

View File

@ -1,36 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class IndexesPhoto extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('photo', function (Blueprint $table) {
$table->index(['signature']);
$table->index(['file_signature']);
$table->index(['duplicate','remove']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('photo', function (Blueprint $table) {
$table->dropIndex(['signature']);
$table->dropIndex(['file_signature']);
$table->dropIndex(['duplicate','remove']);
});
}
}

View File

@ -1,98 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Models\{Software,Video,Make,Model};
class SoftwareidVideos extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('videos', function (Blueprint $table) {
$table->bigInteger('software_id')->unsigned()->nullable();
$table->foreign('software_id')->references('id')->on('software');
});
$po = Video::select(['make','model','software'])
->groupBy(['make','model','software']);
foreach ($po->get() as $o) {
if (! $o->make AND ! $o->model AND ! $o->software)
continue;
$ma = NULL;
dump(['make'=>$o->make,'model'=>$o->model,'software'=>$o->software]);
if ($o->make)
$ma = Make::firstOrCreate(['name'=>$o->make]);
$mo = Model::firstOrCreate([
'name'=>$o->model ?: NULL,
'make_id'=>$ma->id,
]);
$so = Software::firstOrCreate([
'name'=>$o->software ?: NULL,
'model_id'=>$mo->id,
]);
foreach (Video::where('make',$o->make)
->where('model',$o->model)
->where('software',$o->software)
->get() as $p) {
$p->software_id = $so->id;
$p->make = $p->model = $p->software = NULL;
$p->save();
}
}
Schema::table('videos', function (Blueprint $table) {
$table->dropColumn('make');
$table->dropColumn('model');
$table->dropColumn('software');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
/*
Schema::table('videos', function (Blueprint $table) {
$table->string('make',32)->nullable();
$table->string('model',128)->nullable();
$table->string('software')->nullable();
});
*/
foreach (Video::whereNotNULL('software_id')->get() as $p)
{
$s = $p->software()->first();
$p->software = $s->name;
if ($s->model)
$p->model = $s->model->name;
if ($s->model_id AND $s->model->make_id)
$p->make = $s->model->make->name;
$p->software_id = NULL;
$p->save();
}
Schema::table('videos', function (Blueprint $table) {
$table->dropForeign(['software_id']);
$table->dropColumn('software_id');
});
}
}

View File

@ -1,84 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddOverrideKeepAttributes extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('photo', function (Blueprint $table) {
$table->dateTime('created')->nullable();
$table->dateTime('created_manual')->nullable();
$table->boolean('ignore_duplicate')->nullable();
});
Schema::table('videos', function (Blueprint $table) {
$table->dateTime('created')->nullable();
$table->dateTime('created_manual')->nullable();
$table->boolean('ignore_duplicate')->nullable();
});
\App\Models\Photo::each(function($o) {
$o->created = $o->date_created;
$o->date_created = NULL;
$o->save();
});
\App\Models\Video::each(function($o) {
$o->created = $o->date_created;
$o->date_created = NULL;
$o->save();
});
Schema::table('photo', function (Blueprint $table) {
$table->dropColumn('date_created');
});
Schema::table('videos', function (Blueprint $table) {
$table->dropColumn('date_created');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('photos', function (Blueprint $table) {
$table->integer('date_created')->nullable();
});
Schema::table('videos', function (Blueprint $table) {
$table->integer('date_created')->nullable();
});
\App\Models\Photo::each(function($o) {
$o->date_created = $o->created;
$o->created = NULL;
$o->save();
});
\App\Models\Video::each(function($o) {
$o->date_created = $o->created;
$o->created = NULL;
$o->save();
});
Schema::table('videos', function (Blueprint $table) {
$table->dropColumn(['created','created_manual','ignore_duplicate']);
});
Schema::table('photo', function (Blueprint $table) {
$table->dropColumn(['created','created_manual','ignore_duplicate']);
});
}
}