added automation
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?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('automations')) {
|
||||
Schema::create('automations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name', 191);
|
||||
$table->string('code', 64)->unique();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamp('starts_at')->nullable();
|
||||
$table->timestamp('ends_at')->nullable();
|
||||
$table->unsignedTinyInteger('sms_send_hour')->nullable();
|
||||
$table->unsignedTinyInteger('in_app_send_hour')->nullable();
|
||||
$table->string('trigger_type', 16); // schedule|event|price
|
||||
$table->json('trigger_config')->nullable();
|
||||
$table->decimal('last_anchor_price', 18, 2)->nullable();
|
||||
$table->json('conditions')->nullable();
|
||||
$table->json('channels'); // ["sms","in_app"]
|
||||
$table->string('title', 191);
|
||||
$table->text('body');
|
||||
$table->unsignedInteger('cooldown_hours')->default(24);
|
||||
$table->unsignedInteger('max_sends')->nullable();
|
||||
$table->string('logic_fingerprint', 64)->index();
|
||||
$table->unsignedInteger('sent_count')->default(0);
|
||||
$table->unsignedInteger('failed_count')->default(0);
|
||||
$table->timestamp('last_sms_run_at')->nullable();
|
||||
$table->timestamp('last_in_app_run_at')->nullable();
|
||||
$table->unsignedBigInteger('created_by')->nullable()->index();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
if (! Schema::hasTable('automation_sends')) {
|
||||
Schema::create('automation_sends', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('automation_id')->index();
|
||||
$table->unsignedBigInteger('customer_id')->index();
|
||||
$table->string('channel', 16);
|
||||
$table->string('status', 16); // sent|failed
|
||||
$table->text('error')->nullable();
|
||||
$table->timestamps();
|
||||
$table->index(['automation_id', 'customer_id', 'channel']);
|
||||
});
|
||||
}
|
||||
|
||||
if (! Schema::hasTable('automation_delayed_jobs')) {
|
||||
Schema::create('automation_delayed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('automation_id')->index();
|
||||
$table->unsignedBigInteger('customer_id')->index();
|
||||
$table->string('channel', 16);
|
||||
$table->timestamp('run_at')->index();
|
||||
$table->timestamp('processed_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('automation_delayed_jobs');
|
||||
Schema::dropIfExists('automation_sends');
|
||||
Schema::dropIfExists('automations');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user