FEATURE: add soft deletes to content pages

This commit is contained in:
Michal Kváček
2016-09-22 21:57:45 +02:00
parent b982831fbf
commit d5d4216a80
9 changed files with 67 additions and 46 deletions
@@ -0,0 +1,53 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
class AddSoftDeletesToContent extends Migration
{
public function __construct()
{
$platform = Schema::getConnection()
->getDoctrineSchemaManager()
->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('contents', function (Blueprint $table) {
$table->softDeletes()
->after('updated_at');
});
DB::statement("
ALTER TABLE `contents`
CHANGE `status` `status` enum('draft','protected','public') COLLATE 'utf8_unicode_ci' NOT NULL DEFAULT 'draft' AFTER `module_settings`
");
DB::statement('UPDATE contents SET status="protected", deleted_at=NOW() WHERE status=""');
DB::statement('DELETE FROM content_history WHERE new_value="deleted" OR old_value="deleted"');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('contents', function (Blueprint $table) {
$table->dropSoftDeletes();
});
DB::statement("ALTER TABLE `contents`
CHANGE `status` `status` enum('draft','protected','public', 'deleted') COLLATE 'utf8_unicode_ci' NULL DEFAULT 'draft' AFTER `module_settings`;");
}
}