Big changes added events for decisions
This commit is contained in:
+97
@@ -0,0 +1,97 @@
|
||||
<?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
|
||||
{
|
||||
// events table extra columns
|
||||
Schema::table('events', function (Blueprint $table) {
|
||||
if (! Schema::hasColumn('events', 'key')) {
|
||||
$table->string('key')->nullable()->after('id');
|
||||
}
|
||||
if (! Schema::hasColumn('events', 'description')) {
|
||||
$table->text('description')->nullable()->after('name');
|
||||
}
|
||||
if (! Schema::hasColumn('events', 'active')) {
|
||||
$table->boolean('active')->default(true)->after('name');
|
||||
}
|
||||
if (! Schema::hasColumn('events', 'config')) {
|
||||
$table->json('config')->nullable()->after('active');
|
||||
}
|
||||
});
|
||||
|
||||
// decision_event pivot enhancements
|
||||
if (Schema::hasTable('decision_event')) {
|
||||
Schema::table('decision_event', function (Blueprint $table) {
|
||||
if (! Schema::hasColumn('decision_event', 'run_order')) {
|
||||
$table->integer('run_order')->nullable()->after('event_id');
|
||||
}
|
||||
if (! Schema::hasColumn('decision_event', 'active')) {
|
||||
$table->boolean('active')->default(true)->after('run_order');
|
||||
}
|
||||
if (! Schema::hasColumn('decision_event', 'config')) {
|
||||
$table->json('config')->nullable()->after('active');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// logs table
|
||||
if (! Schema::hasTable('decision_event_logs')) {
|
||||
Schema::create('decision_event_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignIdFor(\App\Models\Decision::class)->nullable();
|
||||
$table->foreignIdFor(\App\Models\Event::class, 'event_id');
|
||||
$table->foreignIdFor(\App\Models\Activity::class);
|
||||
$table->string('handler')->nullable();
|
||||
$table->enum('status', ['queued', 'running', 'succeeded', 'failed', 'skipped'])->default('queued');
|
||||
$table->text('message')->nullable();
|
||||
$table->string('idempotency_key')->unique();
|
||||
$table->timestamp('started_at')->nullable();
|
||||
$table->timestamp('finished_at')->nullable();
|
||||
$table->timestamps();
|
||||
$table->index(['decision_id', 'event_id']);
|
||||
$table->index(['activity_id']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (Schema::hasTable('decision_event_logs')) {
|
||||
Schema::drop('decision_event_logs');
|
||||
}
|
||||
|
||||
if (Schema::hasTable('decision_event')) {
|
||||
Schema::table('decision_event', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('decision_event', 'config')) {
|
||||
$table->dropColumn('config');
|
||||
}
|
||||
if (Schema::hasColumn('decision_event', 'active')) {
|
||||
$table->dropColumn('active');
|
||||
}
|
||||
if (Schema::hasColumn('decision_event', 'run_order')) {
|
||||
$table->dropColumn('run_order');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Schema::table('events', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('events', 'config')) {
|
||||
$table->dropColumn('config');
|
||||
}
|
||||
if (Schema::hasColumn('events', 'active')) {
|
||||
$table->dropColumn('active');
|
||||
}
|
||||
if (Schema::hasColumn('events', 'description')) {
|
||||
$table->dropColumn('description');
|
||||
}
|
||||
if (Schema::hasColumn('events', 'key')) {
|
||||
$table->dropColumn('key');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -3,8 +3,8 @@
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Event;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class EventSeeder extends Seeder
|
||||
{
|
||||
@@ -13,12 +13,39 @@ class EventSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$events = [
|
||||
[ 'name' => 'client_case.terrain.add', 'options' => json_encode([]) ]
|
||||
// Seed the new decision event type(s)
|
||||
// Use query builder to satisfy legacy NOT NULL "options" column
|
||||
$rows = [
|
||||
[
|
||||
'key' => 'add_segment',
|
||||
'name' => 'Add segment',
|
||||
'description' => 'Activates a target segment for a contract and deactivates previous ones.',
|
||||
],
|
||||
[
|
||||
'key' => 'archive_contract',
|
||||
'name' => 'Archive contract',
|
||||
'description' => 'Runs ArchiveExecutor for the activity\'s contract using a specified ArchiveSetting.',
|
||||
],
|
||||
[
|
||||
'key' => 'end_field_job',
|
||||
'name' => 'End field job',
|
||||
'description' => 'Dispatches a queued job to finalize field-related processing (implementation-specific).',
|
||||
],
|
||||
];
|
||||
|
||||
foreach($events as $e) {
|
||||
Event::create($e);
|
||||
foreach ($rows as $row) {
|
||||
DB::table('events')->updateOrInsert(
|
||||
['key' => $row['key']],
|
||||
[
|
||||
'name' => $row['name'],
|
||||
'description' => $row['description'],
|
||||
'active' => true,
|
||||
'config' => json_encode([]),
|
||||
'options' => json_encode([]),
|
||||
'updated_at' => now(),
|
||||
'created_at' => now(),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user