42 lines
1.4 KiB
PHP
42 lines
1.4 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
use Illuminate\Database\Migrations\Migration;
|
||
|
|
use Illuminate\Database\Schema\Blueprint;
|
||
|
|
use Illuminate\Support\Facades\Schema;
|
||
|
|
|
||
|
|
return new class extends Migration
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* One row per outbound link found on a captured page, pointing at a different
|
||
|
|
* domain — the edges of a web graph, queryable from either end: "what does this
|
||
|
|
* site link out to" (site_id) or "who links to this domain" (target_domain).
|
||
|
|
*/
|
||
|
|
public function up(): void
|
||
|
|
{
|
||
|
|
Schema::create('backlinks', function (Blueprint $table) {
|
||
|
|
$table->id();
|
||
|
|
$table->foreignId('site_id')->constrained()->cascadeOnDelete();
|
||
|
|
$table->foreignId('site_page_id')->constrained()->cascadeOnDelete();
|
||
|
|
$table->text('target_url');
|
||
|
|
// target_url is unbounded like site_pages.urlkey was — hash it for the
|
||
|
|
// unique index rather than repeat that earlier mistake.
|
||
|
|
$table->char('target_url_hash', 40);
|
||
|
|
$table->string('target_domain')->nullable();
|
||
|
|
$table->string('anchor_text')->nullable();
|
||
|
|
$table->string('rel')->nullable();
|
||
|
|
$table->timestamps();
|
||
|
|
|
||
|
|
$table->unique(['site_page_id', 'target_url_hash']);
|
||
|
|
$table->index('target_domain');
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Reverse the migrations.
|
||
|
|
*/
|
||
|
|
public function down(): void
|
||
|
|
{
|
||
|
|
Schema::dropIfExists('backlinks');
|
||
|
|
}
|
||
|
|
};
|