FEATURE: add soft deletes to users
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class AddSoftDeletesToUsers extends Migration
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$platform = Schema::getConnection()
|
||||
->getDoctrineSchemaManager()
|
||||
->getDatabasePlatform();
|
||||
$platform->registerDoctrineTypeMapping('enum', 'string');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->timestamp('created_at')
|
||||
->nullable()
|
||||
->after('id');
|
||||
$table->timestamp('updated_at')
|
||||
->nullable()
|
||||
->after('created_at');
|
||||
$table->timestamp('deleted_at')
|
||||
->nullable()
|
||||
->after('updated_at');
|
||||
});
|
||||
|
||||
DB::statement("
|
||||
ALTER TABLE `users`
|
||||
CHANGE `status` `status` enum('blocked','active') COLLATE 'utf8_unicode_ci' NOT NULL DEFAULT 'active'
|
||||
");
|
||||
|
||||
DB::statement('UPDATE users SET created_at=NOW(), updated_at=NOW()');
|
||||
DB::statement('UPDATE users SET status="blocked", deleted_at=NOW() WHERE status=""');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropTimestamps();
|
||||
$table->dropSoftDeletes();
|
||||
});
|
||||
|
||||
DB::statement("
|
||||
ALTER TABLE `users`
|
||||
CHANGE `status` `status` enum('blocked','active', 'deleted') COLLATE 'utf8_unicode_ci' NOT NULL DEFAULT 'active'
|
||||
");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user