refactor: improve migrations and update User fields

This commit is contained in:
2025-10-20 21:38:31 +02:00
parent 6811fb43e5
commit f9902c2ed1
14 changed files with 202 additions and 165 deletions

View File

@@ -19,7 +19,11 @@ class User extends Authenticatable
*/
protected $fillable = [
'name',
'first_name',
'last_name',
'phone',
'email',
'role',
'password',
];

View File

@@ -1,20 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void {
Schema::table('users', function (Blueprint $table) {
$table->string('phone')->nullable()->after('email');
$table->enum('role', ['STUDENT','EMPLOYER','ADMIN'])->default('STUDENT')->after('phone');
$table->boolean('is_active')->default(true)->after('role');
});
}
public function down(): void {
Schema::table('users', function (Blueprint $table) {
$table->dropColumn(['phone','role','is_active']);
});
}
};

View File

@@ -1,21 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void {
Schema::create('student_data', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->unique()->constrained('users')->cascadeOnDelete();
$table->string('address')->nullable();
$table->string('personal_email')->nullable();
$table->string('study_field')->nullable();
$table->timestamps();
});
}
public function down(): void {
Schema::dropIfExists('student_data');
}
};

View File

@@ -1,21 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void {
Schema::create('companies', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('ICO', 20)->nullable()->unique();
$table->string('address');
$table->boolean('hiring')->default(false);
$table->timestamps();
});
}
public function down(): void {
Schema::dropIfExists('companies');
}
};

View File

@@ -1,20 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void {
Schema::create('employers', function (Blueprint $table) {
$table->id();
$table->foreignId('company_id')->constrained('companies')->cascadeOnDelete();
$table->foreignId('user_id')->unique()->constrained('users')->cascadeOnDelete();
$table->string('position')->nullable();
$table->timestamps();
});
}
public function down(): void {
Schema::dropIfExists('employers');
}
};

View File

@@ -1,38 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void {
Schema::create('internships', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained('users');
$table->foreignId('company_id')->constrained('companies');
$table->foreignId('employer_id')->nullable()->constrained('employers')->nullOnDelete();
$table->string('agreement')->nullable();
$table->date('start_date');
$table->date('end_date');
$table->enum('semester', ['ZS','LS']);
$table->smallInteger('year_of_study');
$table->text('position_description')->nullable();
$table->boolean('is_paid')->default(false);
$table->unsignedBigInteger('status_id')->nullable();
$table->timestamps();
$table->index(['semester','company_id','user_id','status_id']);
});
}
public function down(): void {
Schema::dropIfExists('internships');
}
};

View File

@@ -1,25 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void {
Schema::create('internship_statuses', function (Blueprint $table) {
$table->id();
$table->foreignId('internship_id')->constrained('internships')->cascadeOnDelete();
$table->enum('status', ['SUBMITTED','CONFIRMED','DENIED','DEFENDED','NOT_DEFENDED']);
$table->timestamp('changed')->useCurrent();
$table->foreignId('modified_by')->nullable()->constrained('users')->nullOnDelete();
$table->text('note')->nullable();
$table->string('source', 30)->default('UI');
$table->timestamps();
$table->index(['internship_id','status']);
});
}
public function down(): void {
Schema::dropIfExists('internship_statuses');
}
};

View File

@@ -1,20 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void {
Schema::table('internships', function (Blueprint $table) {
$table->foreign('status_id')
->references('id')->on('internship_statuses')
->nullOnDelete();
});
}
public function down(): void {
Schema::table('internships', function (Blueprint $table) {
$table->dropForeign(['status_id']);
});
}
};

View File

@@ -0,0 +1,38 @@
<?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::table('users', function (Blueprint $table) {
$table->string('first_name')->nullable(false)->after('name');
$table->string('last_name')->nullable(false)->after('first_name');
$table->string('phone')->nullable(false)->unique()->after('email');
$table->enum("role", ["STUDENT", "EMPLOYER", "ADMIN"])->nullable(false);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropUnique(['phone']);
$table->dropColumn([
'first_name',
'last_name',
'phone',
'role',
]);
});
}
};

View File

@@ -0,0 +1,31 @@
<?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('student_data', function (Blueprint $table) {
$table->id();
$table->foreignId("user_id")->nullable(false)->constrained("users")->onDelete("cascade");
$table->string("address")->nullable(false);
$table->string("personal_email")->nullable(false);
$table->string("study_field")->nullable(false);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('student_data');
}
};

View File

@@ -0,0 +1,31 @@
<?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('companies', function (Blueprint $table) {
$table->id();
$table->string("name")->nullable(false)->unique();
$table->string("address")->nullable(false);
$table->unsignedInteger("ico")->nullable(false)->unique();
$table->boolean("hiring")->nullable(false)->default(false);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('companies');
}
};

View File

@@ -0,0 +1,29 @@
<?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('employers', function (Blueprint $table) {
$table->id();
$table->foreignId("user_id")->nullable(false)->constrained("users")->onDelete("cascade");
$table->foreignId("company_id")->nullable(false)->constrained("companies")->onDelete("cascade");
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('employers');
}
};

View File

@@ -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('internships', function (Blueprint $table) {
$table->id();
$table->foreignId("user_id")->nullable(false)->constrained("users")->onDelete("cascade");
$table->foreignId("company_id")->nullable(false)->constrained("companies")->onDelete("cascade");
$table->dateTimeTz("start")->nullable(false);
$table->dateTimeTz("end")->nullable(false);
$table->unsignedSmallInteger("year_of_study")->nullable(false);
$table->enum("semester", ["WINTER", "SUMMER"])->nullable(false);
$table->string("position_description")->nullable(false);
$table->binary("agreement")->nullable(true);
$table->foreignId("personel_id")->nullable(false)->constrained("users")->onDelete("cascade");
$table->foreignId("status_id")->nullable(false)->constrained("internship_statuses")->onDelete("cascade");
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('internships');
}
};

View File

@@ -0,0 +1,32 @@
<?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('internship_statuses', function (Blueprint $table) {
$table->id();
$table->foreignId("internship_id")->nullable(false)->constrained("internships")->onDelete("cascade");
$table->enum("status", ["SUBMITTED", "CONFIRMED", "DENIED", "DEFENDED", "NOT_DEFENDED"])->nullable(false)->default("SUBMITTED");
$table->dateTimeTz("changed")->nullable(false);
$table->string("note")->nullable(true)->default(null);
$table->foreignId("modified_by")->nullable(false)->constrained("users")->onDelete("cascade");
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('internship_statuses');
}
};