changes 0230092025
This commit is contained in:
@@ -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
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('import_entities', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('key')->unique(); // UI key (plural except person)
|
||||
$table->string('canonical_root'); // canonical root for processor (singular)
|
||||
$table->string('label');
|
||||
$table->json('fields')->nullable(); // array of field names for UI
|
||||
$table->json('field_aliases')->nullable(); // map alias -> canonical field
|
||||
$table->json('aliases')->nullable(); // array of root aliases (e.g., ["contracts","contract"])
|
||||
$table->json('rules')->nullable(); // array of suggestion rules: { pattern, field, priority? }
|
||||
$table->json('ui')->nullable(); // optional UI hints (default_field, order, etc.)
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('import_entities');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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('client_cases', function (Blueprint $table) {
|
||||
if (! Schema::hasColumn('client_cases', 'client_ref')) {
|
||||
$table->string('client_ref', 191)->nullable()->after('person_id');
|
||||
}
|
||||
// Add indexes
|
||||
$table->index('client_ref');
|
||||
// Composite unique per client for client_ref
|
||||
$table->unique(['client_id', 'client_ref']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('client_cases', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('client_cases', 'client_ref')) {
|
||||
// Drop constraints first
|
||||
try {
|
||||
$table->dropUnique('client_cases_client_id_client_ref_unique');
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
try {
|
||||
$table->dropIndex('client_cases_client_ref_index');
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
$table->dropColumn('client_ref');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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('accounts', function (Blueprint $table) {
|
||||
if (! Schema::hasColumn('accounts', 'initial_amount')) {
|
||||
$table->decimal('initial_amount', 18, 4)->nullable()->after('description');
|
||||
$table->index('initial_amount');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('accounts', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('accounts', 'initial_amount')) {
|
||||
$table->dropIndex(['initial_amount']);
|
||||
$table->dropColumn('initial_amount');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,69 @@
|
||||
<?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
|
||||
{
|
||||
if (! Schema::hasTable('imports')) {
|
||||
Schema::create('imports', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->uuid('uuid')->unique();
|
||||
|
||||
// Who initiated the import
|
||||
$table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
|
||||
// Optional template applied to this import (FK can be added separately if needed)
|
||||
$table->foreignId('import_template_id')->nullable();
|
||||
|
||||
// Optional client this import is for (many imports per client)
|
||||
$table->foreignId('client_id')->nullable()->constrained('clients')->nullOnDelete();
|
||||
|
||||
// File/source metadata
|
||||
$table->string('source_type', 12); // csv|xml|xls|xlsx|json
|
||||
$table->string('file_name', 255);
|
||||
$table->string('original_name', 255)->nullable();
|
||||
$table->string('disk', 50)->default('local');
|
||||
$table->string('path', 2048);
|
||||
$table->unsignedBigInteger('size')->nullable(); // bytes
|
||||
$table->string('sheet_name', 64)->nullable(); // for Excel
|
||||
|
||||
// Progress/status
|
||||
$table->string('status', 20)->default('uploaded'); // uploaded|parsing|parsed|validating|importing|completed|failed
|
||||
$table->unsignedInteger('total_rows')->default(0);
|
||||
$table->unsignedInteger('valid_rows')->default(0);
|
||||
$table->unsignedInteger('invalid_rows')->default(0);
|
||||
$table->unsignedInteger('imported_rows')->default(0);
|
||||
$table->timestamp('started_at')->nullable();
|
||||
$table->timestamp('finished_at')->nullable();
|
||||
$table->timestamp('failed_at')->nullable();
|
||||
|
||||
// Diagnostics and flexibility
|
||||
$table->json('error_summary')->nullable();
|
||||
$table->json('meta')->nullable();
|
||||
|
||||
// Helpful indexes
|
||||
$table->index('user_id');
|
||||
$table->index('import_template_id');
|
||||
$table->index('status');
|
||||
$table->index('client_id');
|
||||
$table->index('source_type');
|
||||
$table->index(['disk', 'path']);
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
// Only drop if this migration created it (to be safe if others depend on it)
|
||||
if (Schema::hasTable('imports')) {
|
||||
Schema::drop('imports');
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
<?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
|
||||
{
|
||||
if (! Schema::hasTable('import_rows')) {
|
||||
Schema::create('import_rows', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('import_id')->constrained('imports')->cascadeOnDelete();
|
||||
|
||||
$table->unsignedInteger('row_number');
|
||||
$table->string('sheet_name', 64)->nullable();
|
||||
|
||||
// Type of record represented in this row (person, account, etc.)
|
||||
$table->string('record_type', 50)->nullable();
|
||||
|
||||
// Data and results
|
||||
$table->json('raw_data')->nullable();
|
||||
$table->json('mapped_data')->nullable();
|
||||
$table->string('status', 20)->default('pending'); // pending|valid|invalid|imported|skipped
|
||||
$table->json('errors')->nullable();
|
||||
$table->json('warnings')->nullable();
|
||||
|
||||
// Link to created entity (optional, polymorphic)
|
||||
$table->nullableMorphs('entity'); // entity_type + entity_id
|
||||
|
||||
// Dedup/trace
|
||||
$table->string('fingerprint', 64)->nullable()->index();
|
||||
|
||||
// Helpful indexes
|
||||
$table->index(['import_id', 'status']);
|
||||
$table->index(['import_id', 'row_number']);
|
||||
$table->index('record_type');
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (Schema::hasTable('import_rows')) {
|
||||
Schema::drop('import_rows');
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
<?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
|
||||
{
|
||||
if (! Schema::hasTable('import_mappings')) {
|
||||
Schema::create('import_mappings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('import_id')->constrained('imports')->cascadeOnDelete();
|
||||
|
||||
$table->string('source_column', 255);
|
||||
$table->string('target_field', 255)->nullable();
|
||||
$table->string('transform', 50)->nullable();
|
||||
$table->json('options')->nullable();
|
||||
|
||||
$table->index(['import_id', 'source_column']);
|
||||
$table->index(['import_id', 'target_field']);
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (Schema::hasTable('import_mappings')) {
|
||||
Schema::drop('import_mappings');
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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
|
||||
{
|
||||
if (! Schema::hasTable('import_events')) {
|
||||
Schema::create('import_events', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('import_id')->constrained('imports')->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
|
||||
$table->string('event', 50);
|
||||
$table->string('level', 10)->default('info');
|
||||
$table->text('message')->nullable();
|
||||
$table->json('context')->nullable();
|
||||
|
||||
$table->foreignId('import_row_id')->nullable()->constrained('import_rows')->nullOnDelete();
|
||||
|
||||
$table->index(['import_id', 'event']);
|
||||
$table->index(['import_id', 'level']);
|
||||
$table->index('user_id');
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (Schema::hasTable('import_events')) {
|
||||
Schema::drop('import_events');
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
<?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('contracts', function (Blueprint $table) {
|
||||
// Increase description length from 255 to 500, keep nullable
|
||||
$table->string('description', 500)->nullable()->change();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('contracts', function (Blueprint $table) {
|
||||
// Revert to original length 255, keep nullable
|
||||
$table->string('description', 255)->nullable()->change();
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
<?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('contracts', function (Blueprint $table) {
|
||||
// Switch description to TEXT while keeping it nullable
|
||||
$table->text('description')->nullable()->change();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('contracts', function (Blueprint $table) {
|
||||
// Revert back to VARCHAR(500) nullable
|
||||
$table->string('description', 500)->nullable()->change();
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user