Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.2 kB
2
Indexable
Never
//trigger table db/migration

<?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
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {

        DB::statement('
        CREATE TRIGGER insert_changes AFTER UPDATE ON urlcs FOR EACH ROW
        BEGIN 
        IF old.status <> new.status THEN 
        INSERT INTO event_tables(url_id) VALUES (id);
        END IF;
        END ;
        ');

        Schema::create('event_tables', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('url_id');
            $table->foreign('url_id')->references('url_id')->on('url_emails')->onDelete('cascade');
            $table->boolean('piece_is_sent')->default(false);
            $table->timestamps();

        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        DB::statement('DROP TRIGGER insert_changes');
        Schema::dropIfExists('event_tables');
    }
};
Leave a Comment