FEATURE: add soft deletes to users

This commit is contained in:
Michal Kváček
2016-09-22 22:13:15 +02:00
parent d5d4216a80
commit 0357417163
5 changed files with 66 additions and 8 deletions
@@ -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'
");
}
}