Skip to content

Commit

Permalink
refactor: Move hash migration from command to migration
Browse files Browse the repository at this point in the history
  • Loading branch information
octfx committed Dec 31, 2023
1 parent 46dfaf3 commit 530cda9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 87 deletions.
73 changes: 0 additions & 73 deletions app/Console/Commands/ConvertImageHashTable.php

This file was deleted.

2 changes: 0 additions & 2 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ class Kernel extends ConsoleKernel
PopulateData::class,

CopyTranslationData::class,

ConvertImageHashTable::class,
];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@
*/
public function up(): void
{
Schema::table('comm_link_image_hashes', static function (Blueprint $table) {
$table->binary('pdq_hash1')->nullable()->after('difference_hash');
$table->binary('pdq_hash2')->nullable()->after('pdq_hash1');
$table->binary('pdq_hash3')->nullable()->after('pdq_hash2');
$table->binary('pdq_hash4')->nullable()->after('pdq_hash3');
$table->smallInteger('pdq_quality')->nullable()->after('pdq_hash4');
Schema::dropIfExists('comm_link_image_hashes');
Schema::create('comm_link_image_hashes', static function (Blueprint $table) {
$table->id();
$table->unsignedInteger('comm_link_image_id');
$table->binary('average_hash');
$table->binary('perceptual_hash');
$table->binary('difference_hash');
$table->binary('pdq_hash1');
$table->binary('pdq_hash2');
$table->binary('pdq_hash3');
$table->binary('pdq_hash4');
$table->smallInteger('pdq_quality');
$table->timestamps();

$table->foreign('comm_link_image_id')->references('id')->on('comm_link_images')->onDelete('cascade');
$table->unique('comm_link_image_id');
});
}

Expand All @@ -25,12 +35,17 @@ public function up(): void
*/
public function down(): void
{
Schema::table('comm_link_image_hashes', static function (Blueprint $table) {
$table->dropColumn('pdq_hash1');
$table->dropColumn('pdq_hash2');
$table->dropColumn('pdq_hash3');
$table->dropColumn('pdq_hash4');
$table->dropColumn('pdq_quality');
Schema::dropIfExists('comm_link_image_hashes');
Schema::create('comm_link_image_hashes', static function (Blueprint $table) {
$table->id();
$table->unsignedInteger('comm_link_image_id');
$table->binary('average_hash');
$table->binary('perceptual_hash');
$table->binary('difference_hash');
$table->timestamps();

$table->foreign('comm_link_image_id')->references('id')->on('comm_link_images')->onDelete('cascade');
$table->unique('comm_link_image_id');
});
}
};

0 comments on commit 530cda9

Please sign in to comment.