mirror of
https://koodu.h-i.works/projects/thebadspace
synced 2025-05-06 14:41:02 -05:00
Cleaned up migrations, full text search in model
Migrations were pretty much useless for database set up, so that needed some attention to make setting up the project easier. Now, all necessary tables can be created by running the `artisan migrate` command assuming one has the database parameters set in the .env file also added full text search capabilites through the database set up, which the model itself can use to find locations, so the search has been updated in the appropriate locations as well. still need to add initial account set up and a form for adding sources through the UI, but this was a big step towards letting anyone set up their own version of tbs
This commit is contained in:
parent
8fbf927f2d
commit
07793a413a
@ -26,11 +26,17 @@ class FrontIndexController extends Controller
|
||||
|
||||
public function start()
|
||||
{
|
||||
//for fresh installs that dont have any source data yet
|
||||
$latest_update = 'Never Run';
|
||||
if(count($this->location->getRecent()) != 0)
|
||||
{
|
||||
$latest_update = $this->location->getRecent()[0]->updated_at->format('Y M d');
|
||||
}
|
||||
return view('front.index', [
|
||||
'count' => count($this->location->getActiveLocations()),
|
||||
'sources' => count($this->source->getActive()),
|
||||
'recent' => $this->location->getRecent(),
|
||||
'latest_date' => $this->location->getRecent()[0]->updated_at->format('Y M d'),
|
||||
'latest_date' => $latest_update,
|
||||
'title' => "The Bad Space"
|
||||
]);
|
||||
}
|
||||
|
@ -38,4 +38,13 @@ class Location extends Model
|
||||
"archive_links",
|
||||
"notes",
|
||||
];
|
||||
|
||||
public function scopeSearch($query, $search)
|
||||
{
|
||||
if (!$search) {
|
||||
return $query;
|
||||
}
|
||||
return $query->whereRaw('searchtext @@ to_tsquery(\'english\', ?)', [$search])
|
||||
->orderByRaw('ts_rank(searchtext, to_tsquery(\'english\', ?)) DESC', [$search]);
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,8 @@ class LocationRepository
|
||||
$rawSearch = $terms;
|
||||
$terms = str_replace(",", "", $terms);
|
||||
$terms = str_replace(" ", "|", $terms);
|
||||
$raw = DB::select("SELECT * FROM searchlocations(?)", [$terms]);
|
||||
//$raw = DB::select("SELECT * FROM searchlocations(?)", [$terms]);
|
||||
$raw = Location::search($terms)->get();
|
||||
$results = [];
|
||||
foreach ($raw as $item) {
|
||||
if (($item->block_count + $item->silence_count) >= 2) {
|
||||
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
}
|
||||
};
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
}
|
||||
};
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('personal_access_tokens', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->morphs('tokenable');
|
||||
$table->string('name');
|
||||
$table->string('token', 64)->unique();
|
||||
$table->text('abilities')->nullable();
|
||||
$table->timestamp('last_used_at')->nullable();
|
||||
$table->timestamp('expires_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('personal_access_tokens');
|
||||
}
|
||||
};
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('location', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->uuid('uuid');
|
||||
$table->string('name', length: 255);
|
||||
$table->string('url', length: 255);
|
||||
$table->text('public_comments');
|
||||
$table->json('images')->nullable();
|
||||
$table->boolean('active');
|
||||
$table->string('rating', length: 255);
|
||||
$table->integer('added_by');
|
||||
$table->timestamps(precision: 0);
|
||||
$table->timestamp('deleted_at', precision: 0)->nullable();
|
||||
$table->string('tags', length: 255);
|
||||
$table->integer('block_count')->nullable();
|
||||
$table->integer('silence_count')->nullable();
|
||||
$table->integer('actions_count')->nullable();
|
||||
$table->text('archive_links')->nullable();
|
||||
$table->json('block_vote')->nullable();
|
||||
$table->json('silence_vote')->nullable();
|
||||
$table->text('notes')->nullable();
|
||||
});
|
||||
|
||||
DB::statement("ALTER TABLE location ADD COLUMN searchtext TSVECTOR");
|
||||
DB::statement("UPDATE location SET searchtext = to_tsvector('english', name)");
|
||||
DB::statement("UPDATE location SET searchtext = to_tsvector('english', url)");
|
||||
DB::statement("UPDATE location SET searchtext = to_tsvector('english', public_comments)");
|
||||
DB::statement("UPDATE location SET searchtext = to_tsvector('english', tags)");
|
||||
DB::statement("CREATE INDEX searchtext_gin ON location USING GIN(searchtext)");
|
||||
DB::statement("CREATE TRIGGER ts_searchtext BEFORE INSERT OR UPDATE ON location FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('searchtext', 'pg_catalog.english', 'name', 'url', 'public_comments', 'tags')");
|
||||
}
|
||||
|
||||
//'name', 'url', 'public_comments', 'tags'
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
DB::statement("DROP TRIGGER IF EXISTS tsvector_update_trigger ON location");
|
||||
DB::statement("DROP INDEX IF EXISTS searchtext_gin");
|
||||
DB::statement("ALTER TABLE location DROP COLUMN searchtext");
|
||||
Schema::dropIfExists('location');
|
||||
}
|
||||
};
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('member', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->uuid('uuid');
|
||||
$table->string('handle', length: 255);
|
||||
$table->string('email', length: 255);
|
||||
$table->string('password', length: 255);
|
||||
$table->string('avatar', length: 255)->nullable();
|
||||
$table->string('pronoun', length: 255);
|
||||
$table->string('gender', length: 255)->nullable();
|
||||
$table->boolean('active');
|
||||
$table->integer('role')->nullable();
|
||||
$table->timestamp('created_at', precision: 0);
|
||||
$table->timestamp('last_login', precision: 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('member');
|
||||
}
|
||||
};
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('source', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('url', length: 255);
|
||||
$table->string('type', length: 255);
|
||||
$table->boolean('active');
|
||||
$table->integer('admin_id')->nullable();
|
||||
$table->string('format', length: 255);
|
||||
$table->string('token', length: 255)->nullable();
|
||||
$table->timestamp('last_updated', precision: 0)->nullable();
|
||||
$table->json('list_data')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('source');
|
||||
}
|
||||
};
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('appeal', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->uuid('uuid');
|
||||
$table->string('location', length: 255);
|
||||
$table->string('location_admin', length: 255);
|
||||
$table->string('sponsor', length: 255);
|
||||
$table->text('description');
|
||||
$table->boolean('reviewed')->default(false);
|
||||
$table->boolean('approved')->default(false);
|
||||
$table->timestamps(precision: 0);
|
||||
$table->timestamp('deleted_at', precision: 0)->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('appeal');
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user