Teren-app/database/migrations/2024_10_14_185613_create_person_table.php
2025-11-06 21:54:07 +01:00

114 lines
4.0 KiB
PHP

<?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('person_types', function (Blueprint $table) {
$table->id();
$table->string('name', 50);
$table->string('description', 125)->nullable();
$table->softDeletes();
$table->timestamps();
});
Schema::create('person_groups', function (Blueprint $table) {
$table->id();
$table->string('name', 50);
$table->string('description', 125)->nullable();
$table->string('color_tag', 50)->nullable();
$table->softDeletes();
$table->timestamps();
});
Schema::create('phone_types', function (Blueprint $table) {
$table->id();
$table->string('name', 50);
$table->string('description', 125)->nullable();
$table->softDeletes();
$table->timestamps();
});
Schema::create('address_types', function (Blueprint $table) {
$table->id();
$table->string('name', 50);
$table->string('description', 125)->nullable();
$table->softDeletes();
$table->timestamps();
});
Schema::create('person', function (Blueprint $table) {
$table->id();
$table->uuid('uuid')->unique();
$table->unsignedBigInteger('nu')->default(0);
$table->string('first_name', 255)->nullable();
$table->string('last_name', 255)->nullable();
$table->string('full_name', 255)->nullable();
$table->enum('gender', ['m', 'w'])->nullable();
$table->date('birthday')->nullable();
$table->string('tax_number', 99)->nullable();
$table->string('social_security_number', 99)->nullable();
$table->string('description', 500)->nullable();
$table->foreignId('group_id')->references('id')->on('person_groups');
$table->foreignId('type_id')->references('id')->on('person_types');
$table->unsignedTinyInteger('active')->default(1);
$table->softDeletes();
$table->foreignIdFor(\App\Models\User::class);
$table->timestamps();
});
Schema::create('person_phones', function (Blueprint $table) {
$table->id();
$table->string('nu', 50);
$table->unsignedInteger('country_code')->nullable();
$table->foreignId('type_id')->references('id')->on('phone_types');
$table->string('description', 125)->nullable();
$table->foreignIdFor(\App\Models\Person\Person::class);
$table->unsignedTinyInteger('active')->default(1);
$table->softDeletes();
$table->foreignIdFor(\App\Models\User::class);
$table->timestamps();
});
Schema::create('person_addresses', function (Blueprint $table) {
$table->id();
$table->string('address', 150);
$table->string('country')->nullable();
$table->foreignId('type_id')->references('id')->on('address_types');
$table->string('description', 125)->nullable();
$table->foreignIdFor(\App\Models\Person\Person::class);
$table->unsignedTinyInteger('active')->default(1);
$table->softDeletes();
$table->foreignIdFor(\App\Models\User::class);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('person_types');
Schema::dropIfExists('person_groups');
Schema::dropIfExists('phone_types');
Schema::dropIfExists('address_types');
Schema::dropIfExists('person');
Schema::dropIfExists('person_phones');
Schema::dropIfExists('person_addresses');
}
};