Skip to content

Commit

Permalink
Remove old add_triggers migration and create completely new with new …
Browse files Browse the repository at this point in the history
…code
  • Loading branch information
DariusIII committed Dec 20, 2018
1 parent d664316 commit b193359
Show file tree
Hide file tree
Showing 11 changed files with 289 additions and 64 deletions.
1 change: 1 addition & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
2018-12-20 DariusIII
* Chg: Remove old add_triggers migration and create completely new with new code
* Fix: Replace DB::statement with previously used DB::unprepared for trigger and stored procedure migrations
* Chg: Use user-badge icon for user menu
* Chg: Update fontawesome to version 5.6.3
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"mhor/php-mediainfo": "^4.1",
"monolog/monolog": "^1.22",
"nesbot/carbon": "2.6.1 as 1.35.0",
"ntimyeboah/laravel-database-trigger": "^1.0",
"php-ffmpeg/php-ffmpeg": "^0.13.0",
"php-http/guzzle6-adapter": "^1.1",
"php-http/message": "^1.6",
Expand Down
57 changes: 56 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 0 additions & 63 deletions database/migrations/2018_01_22_215526_add_triggers.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use NtimYeboah\LaravelDatabaseTrigger\TriggerFacade as Schema;

class CreateCheckInsertTrigger extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('check_insert')
->on('releases')
->statement(function () {
return 'IF NEW.searchname REGEXP "[a-fA-F0-9]{32}" OR NEW.name REGEXP "[a-fA-F0-9]{32}" THEN SET NEW.ishashed = 1; END IF;';
})
->before()
->insert();
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('releases.check_insert');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use NtimYeboah\LaravelDatabaseTrigger\TriggerFacade as Schema;

class CreateCheckUpdateTrigger extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('check_update')
->on('releases')
->statement(function () {
return 'IF NEW.searchname REGEXP "[a-fA-F0-9]{32}" OR NEW.name REGEXP "[a-fA-F0-9]{32}" THEN SET NEW.ishashed = 1; END IF;';
})
->before()
->update();
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('releases.check_update');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use NtimYeboah\LaravelDatabaseTrigger\TriggerFacade as Schema;

class CreateCheckRfinsertTrigger extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('check_rfinsert')
->on('release_files')
->statement(function () {
return 'IF NEW.name REGEXP "[a-fA-F0-9]{32}" THEN SET NEW.ishashed = 1; END IF;';
})
->before()
->insert();
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('release_files.check_rfinsert');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use NtimYeboah\LaravelDatabaseTrigger\TriggerFacade as Schema;

class CreateCheckRfupdateTrigger extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('check_rfupdate')
->on('release_files')
->statement(function () {
return 'IF NEW.name REGEXP "[a-fA-F0-9]{32}" THEN SET NEW.ishashed = 1; END IF;';
})
->before()
->update();
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('release_files.check_rfupdate');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use NtimYeboah\LaravelDatabaseTrigger\TriggerFacade as Schema;

class CreateInsertHashesTrigger extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('insert_hashes')
->on('predb')
->statement(function () {
return 'INSERT INTO predb_hashes (hash, predb_id) VALUES (UNHEX(MD5(NEW.title)), NEW.id), (UNHEX(MD5(MD5(NEW.title))), NEW.id), (UNHEX(SHA1(NEW.title)), NEW.id), (UNHEX(SHA2(NEW.title, 256)), NEW.id), (UNHEX(MD5(CONCAT(NEW.title, NEW.requestid))), NEW.id), (UNHEX(MD5(CONCAT(NEW.title, NEW.requestid, NEW.requestid))), NEW.id);';
})
->after()
->update();
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('predb.insert_hashes');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use NtimYeboah\LaravelDatabaseTrigger\TriggerFacade as Schema;

class CreateUpdateHashesTrigger extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('update_hashes')
->on('predb')
->statement(function () {
return 'IF NEW.title != OLD.title THEN DELETE FROM predb_hashes WHERE hash IN ( UNHEX(md5(OLD.title)), UNHEX(md5(md5(OLD.title))), UNHEX(sha1(OLD.title)), UNHEX(sha2(OLD.title, 256)), UNHEX(MD5(CONCAT(OLD.title, OLD.requestid)))) AND predb_id = OLD.id; INSERT INTO predb_hashes (hash, predb_id) VALUES (UNHEX(MD5(NEW.title)), NEW.id), (UNHEX(MD5(MD5(NEW.title))), NEW.id), (UNHEX(SHA1(NEW.title)), NEW.id), (UNHEX(SHA2(NEW.title, 256)), NEW.id), (UNHEX(MD5(CONCAT((NEW.title, NEW.requestid)))), NEW.id), (UNHEX(MD5(CONCAT(NEW.title, NEW.requestid, NEW.requestid))), NEW.id);END IF;';
})
->after()
->update();
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('predb.update_hashes');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use NtimYeboah\LaravelDatabaseTrigger\TriggerFacade as Schema;

class CreateDeleteHashesTrigger extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('delete_hashes')
->on('predb')
->statement(function () {
return 'DELETE FROM predb_hashes WHERE hash IN ( UNHEX(md5(OLD.title)), UNHEX(md5(md5(OLD.title))), UNHEX(sha1(OLD.title)), UNHEX(sha2(OLD.title, 256)), UNHEX(MD5(CONCAT(OLD.title, OLD.requestid))), UNHEX(MD5(CONCAT(OLD.title, OLD.requestid, OLD.requestid)))) AND predb_id = OLD.id;';
})
->after()
->delete();
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('predb.delete_hashes');
}
}

0 comments on commit b193359

Please sign in to comment.