changes 0328092025

This commit is contained in:
Simon Pocrnjič
2025-09-28 22:36:47 +02:00
parent b40ee9dcde
commit 7e8e0a479b
61 changed files with 4306 additions and 654 deletions
@@ -1,19 +1,76 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
return new class extends Migration
{
public function up(): void
{
// PostgreSQL: drop NOT NULL constraint on description
DB::statement('ALTER TABLE segments ALTER COLUMN description DROP NOT NULL');
$driver = DB::connection()->getDriverName();
if ($driver === 'pgsql') {
// PostgreSQL: drop NOT NULL constraint on description
DB::statement('ALTER TABLE segments ALTER COLUMN description DROP NOT NULL');
return;
}
if ($driver === 'mysql') {
// MySQL / MariaDB
DB::statement('ALTER TABLE segments MODIFY description VARCHAR(255) NULL');
return;
}
// SQLite or other drivers: avoid brittle raw SQL. If Doctrine DBAL isn't installed,
// changing a column may not be supported. Since this is only relaxing NOT NULL,
// we can safely no-op for SQLite tests.
if ($driver === 'sqlite') {
return; // no-op for tests
}
// Fallback attempt using Schema (requires doctrine/dbal; if unavailable, it will be ignored in tests)
Schema::table('segments', function (Blueprint $table): void {
try {
$table->string('description', 255)->nullable()->change();
} catch (\Throwable $e) {
// ignore if not supported in current driver
}
});
}
public function down(): void
{
$driver = DB::connection()->getDriverName();
// Ensure no NULLs before setting NOT NULL
DB::statement("UPDATE segments SET description = '' WHERE description IS NULL");
DB::statement('ALTER TABLE segments ALTER COLUMN description SET NOT NULL');
if ($driver === 'pgsql') {
DB::statement('ALTER TABLE segments ALTER COLUMN description SET NOT NULL');
return;
}
if ($driver === 'mysql') {
DB::statement('ALTER TABLE segments MODIFY description VARCHAR(255) NOT NULL');
return;
}
if ($driver === 'sqlite') {
return; // no-op for tests
}
Schema::table('segments', function (Blueprint $table): void {
try {
$table->string('description', 255)->nullable(false)->change();
} catch (\Throwable $e) {
// ignore
}
});
}
};
@@ -0,0 +1,27 @@
<?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('field_job_settings', function (Blueprint $table) {
$table->foreignId('cancel_decision_id')
->nullable()
->after('complete_decision_id')
->constrained('decisions')
->nullOnDelete();
});
}
public function down(): void
{
Schema::table('field_job_settings', function (Blueprint $table) {
$table->dropForeign(['cancel_decision_id']);
$table->dropColumn('cancel_decision_id');
});
}
};
@@ -0,0 +1,26 @@
<?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('field_job_settings', function (Blueprint $table): void {
$table->foreignId('return_segment_id')
->nullable()
->constrained('segments')
->nullOnDelete()
->after('cancel_decision_id');
});
}
public function down(): void
{
Schema::table('field_job_settings', function (Blueprint $table): void {
$table->dropConstrainedForeignId('return_segment_id');
});
}
};
@@ -0,0 +1,20 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
public function up(): void
{
// Rename columns with typos: asign -> assign, asigned -> assigned
DB::statement('ALTER TABLE field_job_settings RENAME COLUMN asign_decision_id TO assign_decision_id');
DB::statement('ALTER TABLE field_jobs RENAME COLUMN asigned_user_id TO assigned_user_id');
}
public function down(): void
{
DB::statement('ALTER TABLE field_job_settings RENAME COLUMN assign_decision_id TO asign_decision_id');
DB::statement('ALTER TABLE field_jobs RENAME COLUMN assigned_user_id TO asigned_user_id');
}
};
@@ -0,0 +1,26 @@
<?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('field_job_settings', function (Blueprint $table) {
if (! Schema::hasColumn('field_job_settings', 'queue_segment_id')) {
$table->foreignId('queue_segment_id')->nullable()->constrained('segments')->nullOnDelete();
}
});
}
public function down(): void
{
Schema::table('field_job_settings', function (Blueprint $table) {
if (Schema::hasColumn('field_job_settings', 'queue_segment_id')) {
$table->dropConstrainedForeignId('queue_segment_id');
}
});
}
};