1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-25 17:26:43 +00:00

Add migration

This commit is contained in:
Daniel Supernault 2022-12-27 02:42:50 -07:00
parent d33bc2d1d6
commit 3d2656bb02
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -0,0 +1,48 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Hashtag;
use App\StatusHashtag;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('hashtags', function (Blueprint $table) {
$table->unsignedInteger('cached_count')->nullable();
$table->boolean('can_trend')->nullable()->index()->after('slug');
$table->boolean('can_search')->nullable()->index()->after('can_trend');
$table->index('is_nsfw');
$table->index('is_banned');
});
foreach(Hashtag::cursor() as $hashtag) {
$count = StatusHashtag::whereHashtagId($hashtag->id)->count();
$hashtag->cached_count = $count;
$hashtag->save();
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('hashtags', function (Blueprint $table) {
$table->dropColumn('cached_count');
$table->dropColumn('can_trend');
$table->dropColumn('can_search');
$table->dropIndex('hashtags_is_nsfw_index');
$table->dropIndex('hashtags_is_banned_index');
});
}
};