mirror of
https://github.com/flarum/core.git
synced 2025-07-31 05:30:38 +02:00
Revert notifications_from table
I didn't think this change through and it's going to be too difficult to implement right now. It can wait until we do the notifications revamp. For now reverting back to the old structure, with the `sender_id` column renamed to `from_user_id`.
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Flarum\Database\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
return Migration::createTable(
|
||||
'notifications_from',
|
||||
function (Blueprint $table) {
|
||||
$table->integer('id')->unsigned();
|
||||
$table->integer('from_user_id')->unsigned();
|
||||
|
||||
$table->foreign('id')->references('id')->on('notifications')->onDelete('cascade');
|
||||
$table->foreign('from_user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
}
|
||||
);
|
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Schema\Builder;
|
||||
|
||||
return [
|
||||
'up' => function (Builder $schema) {
|
||||
$query = $schema->getConnection()->table('notifications')
|
||||
->whereExists(function ($query) {
|
||||
$query->selectRaw(1)->from('users')->whereRaw('id = sender_id');
|
||||
});
|
||||
|
||||
foreach ($query->cursor() as $notification) {
|
||||
$insert = [
|
||||
'id' => $notification->id,
|
||||
'from_user_id' => $notification->sender_id
|
||||
];
|
||||
|
||||
$schema->getConnection()->table('notifications_from')->updateOrInsert($insert, $insert);
|
||||
}
|
||||
},
|
||||
|
||||
'down' => function (Builder $schema) {
|
||||
$schema->getConnection()->table('notifications_from')->truncate();
|
||||
}
|
||||
];
|
@@ -16,9 +16,10 @@ use Illuminate\Database\Schema\Builder;
|
||||
return [
|
||||
'up' => function (Builder $schema) {
|
||||
$schema->table('notifications', function (Blueprint $table) {
|
||||
$table->dropColumn('sender_id', 'subject_type');
|
||||
$table->dropColumn('subject_type');
|
||||
|
||||
$table->renameColumn('time', 'created_at');
|
||||
$table->renameColumn('sender_id', 'from_user_id');
|
||||
|
||||
$table->dateTime('read_at')->nullable();
|
||||
});
|
||||
@@ -34,10 +35,10 @@ return [
|
||||
|
||||
'down' => function (Builder $schema) {
|
||||
$schema->table('notifications', function (Blueprint $table) {
|
||||
$table->integer('sender_id')->unsigned()->nullable();
|
||||
$table->string('subject_type', 200)->nullable();
|
||||
|
||||
$table->renameColumn('created_at', 'time');
|
||||
$table->renameColumn('from_user_id', 'sender_id');
|
||||
|
||||
$table->boolean('is_read');
|
||||
});
|
||||
|
@@ -23,14 +23,22 @@ return [
|
||||
})
|
||||
->delete();
|
||||
|
||||
$schema->getConnection()
|
||||
->table('notifications')
|
||||
->whereNotExists(function ($query) {
|
||||
$query->selectRaw(1)->from('users')->whereRaw('id = from_user_id');
|
||||
})
|
||||
->update(['from_user_id' => null]);
|
||||
|
||||
$schema->table('notifications', function (Blueprint $table) {
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
$table->foreign('from_user_id')->references('id')->on('users')->onDelete('set null');
|
||||
});
|
||||
},
|
||||
|
||||
'down' => function (Builder $schema) {
|
||||
$schema->table('notifications', function (Blueprint $table) {
|
||||
$table->dropForeign(['user_id']);
|
||||
$table->dropForeign(['user_id', 'from_user_id']);
|
||||
});
|
||||
}
|
||||
];
|
||||
|
Reference in New Issue
Block a user