Files
BarangaySystem/database/migrations/2026_04_19_100001_create_chapters_table.php
2026-06-06 18:43:00 +08:00

36 lines
1.3 KiB
PHP

<?php
use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;
class CreateChaptersTable extends Migration
{
public function up(): void
{
Schema::create('chapters', function (Blueprint $table) {
$table->id();
$table->string('hashkey')->unique();
$table->string('name');
$table->enum('level', ['national', 'region', 'province', 'city', 'barangay']);
$table->unsignedBigInteger('parent_id')->nullable();
$table->string('location_key')->nullable()->comment('Normalized slug for auto-matching UserInfo address fields');
$table->decimal('lat', 10, 7)->nullable();
$table->decimal('lng', 10, 7)->nullable();
$table->boolean('is_active')->default(true);
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
$table->timestamps();
$table->foreign('parent_id')->references('id')->on('chapters')->nullOnDelete();
$table->index(['level', 'is_active']);
$table->index('location_key');
});
}
public function down(): void
{
Schema::dropIfExists('chapters');
}
}