From 2d04c8ccbbc80450d08f605dd4ffed721774032d Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 28 Aug 2024 13:19:30 +1000 Subject: [PATCH] Rebuild database migrations --- .../migrations/0010-make_model_software.php | 56 ++++++++ database/migrations/0020-make_photo.php | 59 ++++++++ database/migrations/0030-make_videos.php | 65 +++++++++ ..._people_table.php => 0040-make_people.php} | 14 +- ...eate_tags_table.php => 0042-make_tags.php} | 15 +-- .../2016_06_03_055603_create_photo_table.php | 48 ------- ...06_03_055604_create_photo_people_table.php | 24 ++-- ...16_06_03_055604_create_photo_tag_table.php | 18 +-- ...add_foreign_keys_to_photo_people_table.php | 37 ----- ...05_add_foreign_keys_to_photo_tag_table.php | 37 ----- .../2016_07_01_131722_rename_photo_people.php | 37 ----- .../2016_07_01_205600_create_videos_table.php | 53 -------- ...07_03_155604_create_person_video_table.php | 7 +- ...17_07_03_155604_create_tag_video_table.php | 7 +- ...2018_01_10_000000_photos_rename_fields.php | 34 ----- .../2018_01_11_090453_VideoAddScanned.php | 51 ------- .../2018_01_13_120330_PhotoAddIndex.php | 54 -------- .../2019_11_15_214900_change_model_photo.php | 28 ---- .../2019_11_22_203904_revert_index_photo.php | 54 -------- ...9_11_23_125316_create_makemodel_tables.php | 127 ------------------ .../2019_12_15_210931_indexes_photo.php | 36 ----- .../2019_12_26_125230_softwareid_videos.php | 98 -------------- ...27_164640_add_override_keep_attributes.php | 84 ------------ 23 files changed, 225 insertions(+), 818 deletions(-) create mode 100644 database/migrations/0010-make_model_software.php create mode 100644 database/migrations/0020-make_photo.php create mode 100644 database/migrations/0030-make_videos.php rename database/migrations/{2016_06_03_055604_create_people_table.php => 0040-make_people.php} (76%) rename database/migrations/{2016_06_03_055604_create_tags_table.php => 0042-make_tags.php} (65%) delete mode 100644 database/migrations/2016_06_03_055603_create_photo_table.php delete mode 100644 database/migrations/2016_06_03_055605_add_foreign_keys_to_photo_people_table.php delete mode 100644 database/migrations/2016_06_03_055605_add_foreign_keys_to_photo_tag_table.php delete mode 100644 database/migrations/2016_07_01_131722_rename_photo_people.php delete mode 100644 database/migrations/2016_07_01_205600_create_videos_table.php delete mode 100644 database/migrations/2018_01_10_000000_photos_rename_fields.php delete mode 100644 database/migrations/2018_01_11_090453_VideoAddScanned.php delete mode 100644 database/migrations/2018_01_13_120330_PhotoAddIndex.php delete mode 100644 database/migrations/2019_11_15_214900_change_model_photo.php delete mode 100644 database/migrations/2019_11_22_203904_revert_index_photo.php delete mode 100644 database/migrations/2019_11_23_125316_create_makemodel_tables.php delete mode 100644 database/migrations/2019_12_15_210931_indexes_photo.php delete mode 100644 database/migrations/2019_12_26_125230_softwareid_videos.php delete mode 100644 database/migrations/2019_12_27_164640_add_override_keep_attributes.php diff --git a/database/migrations/0010-make_model_software.php b/database/migrations/0010-make_model_software.php new file mode 100644 index 0000000..e285983 --- /dev/null +++ b/database/migrations/0010-make_model_software.php @@ -0,0 +1,56 @@ +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'); + } +}; \ No newline at end of file diff --git a/database/migrations/0020-make_photo.php b/database/migrations/0020-make_photo.php new file mode 100644 index 0000000..a166c0c --- /dev/null +++ b/database/migrations/0020-make_photo.php @@ -0,0 +1,59 @@ +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'); + } +}; \ No newline at end of file diff --git a/database/migrations/0030-make_videos.php b/database/migrations/0030-make_videos.php new file mode 100644 index 0000000..5e8e60c --- /dev/null +++ b/database/migrations/0030-make_videos.php @@ -0,0 +1,65 @@ +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'); + } +}; \ No newline at end of file diff --git a/database/migrations/2016_06_03_055604_create_people_table.php b/database/migrations/0040-make_people.php similarity index 76% rename from database/migrations/2016_06_03_055604_create_people_table.php rename to database/migrations/0040-make_people.php index 617dd70..ebd2422 100644 --- a/database/migrations/2016_06_03_055604_create_people_table.php +++ b/database/migrations/0040-make_people.php @@ -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'); } - -} +}; diff --git a/database/migrations/2016_06_03_055604_create_tags_table.php b/database/migrations/0042-make_tags.php similarity index 65% rename from database/migrations/2016_06_03_055604_create_tags_table.php rename to database/migrations/0042-make_tags.php index 5189df5..5a78257 100644 --- a/database/migrations/2016_06_03_055604_create_tags_table.php +++ b/database/migrations/0042-make_tags.php @@ -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->string('description', 45)->nullable(); + $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'); } - -} +}; \ No newline at end of file diff --git a/database/migrations/2016_06_03_055603_create_photo_table.php b/database/migrations/2016_06_03_055603_create_photo_table.php deleted file mode 100644 index aebad5e..0000000 --- a/database/migrations/2016_06_03_055603_create_photo_table.php +++ /dev/null @@ -1,48 +0,0 @@ -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'); - } - -} diff --git a/database/migrations/2016_06_03_055604_create_photo_people_table.php b/database/migrations/2016_06_03_055604_create_photo_people_table.php index 4109647..887fbc3 100644 --- a/database/migrations/2016_06_03_055604_create_photo_people_table.php +++ b/database/migrations/2016_06_03_055604_create_photo_people_table.php @@ -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'); } - -} +}; \ No newline at end of file diff --git a/database/migrations/2016_06_03_055604_create_photo_tag_table.php b/database/migrations/2016_06_03_055604_create_photo_tag_table.php index 08153d9..02399b3 100644 --- a/database/migrations/2016_06_03_055604_create_photo_tag_table.php +++ b/database/migrations/2016_06_03_055604_create_photo_tag_table.php @@ -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'); } - -} +}; \ No newline at end of file diff --git a/database/migrations/2016_06_03_055605_add_foreign_keys_to_photo_people_table.php b/database/migrations/2016_06_03_055605_add_foreign_keys_to_photo_people_table.php deleted file mode 100644 index 942bb80..0000000 --- a/database/migrations/2016_06_03_055605_add_foreign_keys_to_photo_people_table.php +++ /dev/null @@ -1,37 +0,0 @@ -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'); - }); - } - -} diff --git a/database/migrations/2016_06_03_055605_add_foreign_keys_to_photo_tag_table.php b/database/migrations/2016_06_03_055605_add_foreign_keys_to_photo_tag_table.php deleted file mode 100644 index 60a8191..0000000 --- a/database/migrations/2016_06_03_055605_add_foreign_keys_to_photo_tag_table.php +++ /dev/null @@ -1,37 +0,0 @@ -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'); - }); - } - -} diff --git a/database/migrations/2016_07_01_131722_rename_photo_people.php b/database/migrations/2016_07_01_131722_rename_photo_people.php deleted file mode 100644 index ad7f18c..0000000 --- a/database/migrations/2016_07_01_131722_rename_photo_people.php +++ /dev/null @@ -1,37 +0,0 @@ -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'); - } -} diff --git a/database/migrations/2016_07_01_205600_create_videos_table.php b/database/migrations/2016_07_01_205600_create_videos_table.php deleted file mode 100644 index 019b752..0000000 --- a/database/migrations/2016_07_01_205600_create_videos_table.php +++ /dev/null @@ -1,53 +0,0 @@ -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'); - } - -} diff --git a/database/migrations/2017_07_03_155604_create_person_video_table.php b/database/migrations/2017_07_03_155604_create_person_video_table.php index 5a4286e..fed883a 100644 --- a/database/migrations/2017_07_03_155604_create_person_video_table.php +++ b/database/migrations/2017_07_03_155604_create_person_video_table.php @@ -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']); }); } diff --git a/database/migrations/2017_07_03_155604_create_tag_video_table.php b/database/migrations/2017_07_03_155604_create_tag_video_table.php index a842d0e..4177654 100644 --- a/database/migrations/2017_07_03_155604_create_tag_video_table.php +++ b/database/migrations/2017_07_03_155604_create_tag_video_table.php @@ -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']); }); } diff --git a/database/migrations/2018_01_10_000000_photos_rename_fields.php b/database/migrations/2018_01_10_000000_photos_rename_fields.php deleted file mode 100644 index e67ce72..0000000 --- a/database/migrations/2018_01_10_000000_photos_rename_fields.php +++ /dev/null @@ -1,34 +0,0 @@ -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'); - }); - } -} diff --git a/database/migrations/2018_01_11_090453_VideoAddScanned.php b/database/migrations/2018_01_11_090453_VideoAddScanned.php deleted file mode 100644 index dea9f30..0000000 --- a/database/migrations/2018_01_11_090453_VideoAddScanned.php +++ /dev/null @@ -1,51 +0,0 @@ -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'); - }); - } -} diff --git a/database/migrations/2018_01_13_120330_PhotoAddIndex.php b/database/migrations/2018_01_13_120330_PhotoAddIndex.php deleted file mode 100644 index 99d2a45..0000000 --- a/database/migrations/2018_01_13_120330_PhotoAddIndex.php +++ /dev/null @@ -1,54 +0,0 @@ -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']); - }); - } -} diff --git a/database/migrations/2019_11_15_214900_change_model_photo.php b/database/migrations/2019_11_15_214900_change_model_photo.php deleted file mode 100644 index 18c36df..0000000 --- a/database/migrations/2019_11_15_214900_change_model_photo.php +++ /dev/null @@ -1,28 +0,0 @@ -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']); - }); - } -} diff --git a/database/migrations/2019_11_23_125316_create_makemodel_tables.php b/database/migrations/2019_11_23_125316_create_makemodel_tables.php deleted file mode 100644 index 3580d42..0000000 --- a/database/migrations/2019_11_23_125316_create_makemodel_tables.php +++ /dev/null @@ -1,127 +0,0 @@ -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'); - } -} diff --git a/database/migrations/2019_12_15_210931_indexes_photo.php b/database/migrations/2019_12_15_210931_indexes_photo.php deleted file mode 100644 index d0a3d80..0000000 --- a/database/migrations/2019_12_15_210931_indexes_photo.php +++ /dev/null @@ -1,36 +0,0 @@ -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']); - }); - } -} diff --git a/database/migrations/2019_12_26_125230_softwareid_videos.php b/database/migrations/2019_12_26_125230_softwareid_videos.php deleted file mode 100644 index d0b5b7c..0000000 --- a/database/migrations/2019_12_26_125230_softwareid_videos.php +++ /dev/null @@ -1,98 +0,0 @@ -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'); - }); - } -} diff --git a/database/migrations/2019_12_27_164640_add_override_keep_attributes.php b/database/migrations/2019_12_27_164640_add_override_keep_attributes.php deleted file mode 100644 index 09e8d89..0000000 --- a/database/migrations/2019_12_27_164640_add_override_keep_attributes.php +++ /dev/null @@ -1,84 +0,0 @@ -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']); - }); - } -}