Skip to content
This repository has been archived by the owner on May 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #89 from js361014/migration-check-payload
Browse files Browse the repository at this point in the history
Add event_payload_check trigger migration
  • Loading branch information
butschster committed Aug 3, 2022
2 parents c9a82ae + 32c3ae7 commit 4ee8489
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Cycle\Migrations\Migration;
use Illuminate\Support\Facades\DB;

class OrmDefault9ad6069564d4b7abde89765793a82029 extends Migration
{
protected const DATABASE = 'default';

public function up()
{
if (config('database.connections.mysql')) {
DB::unprepared('drop trigger if exists trigger_event_payload_check');
DB::unprepared("
create trigger trigger_event_payload_check before insert on events
for each row
begin
declare msg varchar(128);
if (not JSON_VALID(new.payload)) then
set msg = concat('trigger_event_payload_check: Trying to insert invalid payload in events: ', LEFT(new.payload, 10), ' (showing 10 first characters)');
signal sqlstate '45000' set message_text = msg;
end if;
end;"
);
}
}

public function down()
{
if (config('database.connections.mysql')) {
DB::unprepared('drop trigger if exists trigger_event_payload_check');
}
}
}

0 comments on commit 4ee8489

Please sign in to comment.