FEATURE: add soft deletes to content pages
This commit is contained in:
@@ -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`;");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user