From 9366c43a655303d6623dec4f8887e90a11172eea Mon Sep 17 00:00:00 2001 From: Peter Deltchev Date: Wed, 15 Jun 2016 00:58:16 -0700 Subject: [PATCH] Added a unique constraint to cache keys. --- .../2016_06_15_075023_fix_cache_table.php | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 database/migrations/2016_06_15_075023_fix_cache_table.php diff --git a/database/migrations/2016_06_15_075023_fix_cache_table.php b/database/migrations/2016_06_15_075023_fix_cache_table.php new file mode 100644 index 00000000..c2ef10f1 --- /dev/null +++ b/database/migrations/2016_06_15_075023_fix_cache_table.php @@ -0,0 +1,53 @@ +. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Migrations\Migration; + +class FixCacheTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + // Wipe the cache table - it's in a corrupt state because + // it allowed duplicate keys to exist until now. + DB::table('cache')->delete(); + + Schema::table('cache', function (Blueprint $table) { + $table->unique('key'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('cache', function (Blueprint $table) { + $table->dropUnique('cache_key_unique'); + }); + } +}