1
0
mirror of https://github.com/flarum/core.git synced 2025-08-06 16:36:47 +02:00

Merge branch 'master' into 1236-user-preferences

This commit is contained in:
Daniël Klabbers
2018-12-13 20:19:47 +01:00
committed by GitHub
516 changed files with 13935 additions and 62875 deletions

View File

@@ -19,15 +19,27 @@ return [
$table->renameColumn('lifetime', 'lifetime_seconds');
$table->renameColumn('last_activity', 'last_activity_at');
$table->dateTime('created_at');
$table->integer('user_id')->unsigned()->change();
});
// Use a separate schema instance because this column gets renamed
// in the first one.
$schema->table('access_tokens', function (Blueprint $table) {
$table->dateTime('last_activity_at')->change();
});
},
'down' => function (Builder $schema) {
$schema->table('access_tokens', function (Blueprint $table) {
$table->integer('last_activity_at')->change();
});
$schema->table('access_tokens', function (Blueprint $table) {
$table->renameColumn('token', 'id');
$table->renameColumn('lifetime_seconds', 'lifetime');
$table->renameColumn('last_activity_at', 'last_activity');
$table->dropColumn('created_at');
$table->renameColumn('token', 'id');
$table->integer('user_id')->change();
});
}
];

View File

@@ -0,0 +1,41 @@
<?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;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
// Delete rows with non-existent users so that we will be able to create
// foreign keys without any issues.
$schema->getConnection()
->table('access_tokens')
->whereNotExists(function ($query) {
$query->selectRaw(1)->from('users')->whereColumn('id', 'user_id');
})
->delete();
$schema->table('access_tokens', function (Blueprint $table) use ($schema) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('access_tokens', function (Blueprint $table) use ($schema) {
$table->dropForeign(['user_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@@ -1,27 +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\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->table('access_tokens', function (Blueprint $table) {
$table->dateTime('last_activity_at')->change();
});
},
'down' => function (Builder $schema) {
$schema->table('access_tokens', function (Blueprint $table) {
$table->integer('last_activity_at')->change();
});
}
];

View File

@@ -9,12 +9,21 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->table('api_keys', function (Blueprint $table) {
$schema->table('api_keys', function (Blueprint $table) use ($schema) {
$table->dropPrimary(['id']);
$table->renameColumn('id', 'key');
$table->unique('key');
Migration::fixIndexNames($schema, $table);
});
$schema->table('api_keys', function (Blueprint $table) use ($schema) {
$table->increments('id');
$table->string('allowed_ips')->nullable();
$table->string('scopes')->nullable();
@@ -23,13 +32,25 @@ return [
$table->dateTime('last_activity_at')->nullable();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('api_keys', function (Blueprint $table) {
$schema->table('api_keys', function (Blueprint $table) use ($schema) {
$table->dropForeign(['user_id']);
$table->dropColumn('id', 'allowed_ips', 'user_id', 'scopes', 'created_at');
Migration::fixIndexNames($schema, $table);
});
$schema->table('api_keys', function (Blueprint $table) use ($schema) {
$table->dropUnique(['key']);
$table->renameColumn('key', 'id');
$table->primary('id');
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@@ -9,19 +9,6 @@
* file that was distributed with this source code.
*/
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
use Flarum\Database\Migration;
return [
'up' => function (Builder $schema) {
$schema->table('registration_tokens', function (Blueprint $table) {
$table->renameColumn('id', 'token');
});
},
'down' => function (Builder $schema) {
$schema->table('registration_tokens', function (Blueprint $table) {
$table->renameColumn('token', 'id');
});
}
];
return Migration::renameColumn('registration_tokens', 'id', 'token');

View File

@@ -0,0 +1,27 @@
<?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) {
// do this manually because dbal doesn't recognize timestamp columns
$connection = $schema->getConnection();
$prefix = $connection->getTablePrefix();
$connection->statement("ALTER TABLE {$prefix}registration_tokens MODIFY created_at DATETIME");
},
'down' => function (Builder $schema) {
$connection = $schema->getConnection();
$prefix = $connection->getTablePrefix();
$connection->statement("ALTER TABLE {$prefix}registration_tokens MODIFY created_at TIMESTAMP");
}
];

View File

@@ -1,45 +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\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->table('discussions', function (Blueprint $table) {
$table->renameColumn('comments_count', 'comment_count');
$table->renameColumn('participants_count', 'participant_count');
$table->renameColumn('number_index', 'post_number_index');
$table->renameColumn('start_time', 'created_at');
$table->renameColumn('start_user_id', 'user_id');
$table->renameColumn('start_post_id', 'first_post_id');
$table->renameColumn('last_time', 'last_posted_at');
$table->renameColumn('last_user_id', 'last_posted_user_id');
$table->renameColumn('hide_time', 'hidden_at');
$table->renameColumn('hide_user_id', 'hidden_user_id');
});
},
'down' => function (Builder $schema) {
$schema->table('discussions', function (Blueprint $table) {
$table->renameColumn('comment_count', 'comments_count');
$table->renameColumn('participant_count', 'participants_count');
$table->renameColumn('post_number_index', 'number_index');
$table->renameColumn('created_at', 'start_time');
$table->renameColumn('user_id', 'start_user_id');
$table->renameColumn('first_post_id', 'start_post_id');
$table->renameColumn('last_posted_at', 'last_time');
$table->renameColumn('last_posted_user_id', 'last_user_id');
$table->renameColumn('hidden_at', 'hide_time');
$table->renameColumn('hidden_user_id', 'hide_user_id');
});
}
];

View File

@@ -0,0 +1,25 @@
<?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;
return Migration::renameColumns('discussions', [
'comments_count' => 'comment_count',
'participants_count' => 'participant_count',
'number_index' => 'post_number_index',
'start_time' => 'created_at',
'start_user_id' => 'user_id',
'start_post_id' => 'first_post_id',
'last_time' => 'last_posted_at',
'last_user_id' => 'last_posted_user_id',
'hide_time' => 'hidden_at',
'hide_user_id' => 'hidden_user_id'
]);

View File

@@ -0,0 +1,59 @@
<?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\Query\Expression;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
// Set non-existent entity IDs to NULL so that we will be able to create
// foreign keys without any issues.
$connection = $schema->getConnection();
$selectId = function ($table, $column) use ($connection) {
return new Expression(
'('.$connection->table($table)->whereColumn('id', $column)->select('id')->toSql().')'
);
};
$connection->table('discussions')->update([
'user_id' => $selectId('users', 'user_id'),
'last_posted_user_id' => $selectId('users', 'last_posted_user_id'),
'hidden_user_id' => $selectId('users', 'hidden_user_id'),
'first_post_id' => $selectId('posts', 'first_post_id'),
'last_post_id' => $selectId('posts', 'last_post_id'),
]);
$schema->table('discussions', function (Blueprint $table) use ($schema) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('set null');
$table->foreign('last_posted_user_id')->references('id')->on('users')->onDelete('set null');
$table->foreign('hidden_user_id')->references('id')->on('users')->onDelete('set null');
$table->foreign('first_post_id')->references('id')->on('posts')->onDelete('set null');
$table->foreign('last_post_id')->references('id')->on('posts')->onDelete('set null');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('discussions', function (Blueprint $table) use ($schema) {
$table->dropForeign(['user_id']);
$table->dropForeign(['last_posted_user_id']);
$table->dropForeign(['hidden_user_id']);
$table->dropForeign(['first_post_id']);
$table->dropForeign(['last_post_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@@ -1,22 +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) {
$schema->rename('users_discussions', 'discussions_users');
},
'down' => function (Builder $schema) {
$schema->rename('discussions_users', 'users_discussions');
}
];

View File

@@ -0,0 +1,14 @@
<?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;
return Migration::renameTable('users_discussions', 'discussion_user');

View File

@@ -0,0 +1,17 @@
<?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;
return Migration::renameColumns('discussion_user', [
'read_time' => 'last_read_at',
'read_number' => 'last_read_post_number'
]);

View File

@@ -1,29 +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\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->table('discussions_users', function (Blueprint $table) {
$table->renameColumn('read_time', 'last_read_at');
$table->renameColumn('read_number', 'last_read_post_number');
});
},
'down' => function (Builder $schema) {
$schema->table('discussions_users', function (Blueprint $table) {
$table->renameColumn('last_read_at', 'read_time');
$table->renameColumn('last_read_post_number', 'read_number');
});
}
];

View File

@@ -0,0 +1,46 @@
<?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;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
// Delete rows with non-existent entities so that we will be able to create
// foreign keys without any issues.
$connection = $schema->getConnection();
$connection->table('discussion_user')
->whereNotExists(function ($query) {
$query->selectRaw(1)->from('users')->whereColumn('id', 'user_id');
})
->orWhereNotExists(function ($query) {
$query->selectRaw(1)->from('discussions')->whereColumn('id', 'discussion_id');
})
->delete();
$schema->table('discussion_user', function (Blueprint $table) use ($schema) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('discussion_id')->references('id')->on('discussions')->onDelete('cascade');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('discussion_user', function (Blueprint $table) use ($schema) {
$table->dropForeign(['user_id']);
$table->dropForeign(['discussion_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@@ -1,27 +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\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->table('email_tokens', function (Blueprint $table) {
$table->renameColumn('id', 'token');
});
},
'down' => function (Builder $schema) {
$schema->table('email_tokens', function (Blueprint $table) {
$table->renameColumn('token', 'id');
});
}
];

View File

@@ -11,4 +11,4 @@
use Flarum\Database\Migration;
return Migration::renameTable('permissions', 'groups_permissions');
return Migration::renameColumn('email_tokens', 'id', 'token');

View File

@@ -0,0 +1,41 @@
<?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;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
// Delete rows with non-existent users so that we will be able to create
// foreign keys without any issues.
$schema->getConnection()
->table('email_tokens')
->whereNotExists(function ($query) {
$query->selectRaw(1)->from('users')->whereColumn('id', 'user_id');
})
->delete();
$schema->table('email_tokens', function (Blueprint $table) use ($schema) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('email_tokens', function (Blueprint $table) use ($schema) {
$table->dropForeign(['user_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@@ -0,0 +1,27 @@
<?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) {
// do this manually because dbal doesn't recognize timestamp columns
$connection = $schema->getConnection();
$prefix = $connection->getTablePrefix();
$connection->statement("ALTER TABLE {$prefix}email_tokens MODIFY created_at DATETIME");
},
'down' => function (Builder $schema) {
$connection = $schema->getConnection();
$prefix = $connection->getTablePrefix();
$connection->statement("ALTER TABLE {$prefix}email_tokens MODIFY created_at TIMESTAMP");
}
];

View File

@@ -0,0 +1,14 @@
<?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;
return Migration::renameTable('permissions', 'group_permission');

View File

@@ -0,0 +1,41 @@
<?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;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
// Delete rows with non-existent groups so that we will be able to create
// foreign keys without any issues.
$schema->getConnection()
->table('group_permission')
->whereNotExists(function ($query) {
$query->selectRaw(1)->from('groups')->whereColumn('id', 'group_id');
})
->delete();
$schema->table('group_permission', function (Blueprint $table) use ($schema) {
$table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('group_permission', function (Blueprint $table) use ($schema) {
$table->dropForeign(['group_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@@ -0,0 +1,46 @@
<?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;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
// Delete rows with non-existent entities so that we will be able to create
// foreign keys without any issues.
$schema->getConnection()
->table('group_user')
->whereNotExists(function ($query) {
$query->selectRaw(1)->from('users')->whereColumn('id', 'user_id');
})
->orWhereNotExists(function ($query) {
$query->selectRaw(1)->from('groups')->whereColumn('id', 'group_id');
})
->delete();
$schema->table('group_user', function (Blueprint $table) use ($schema) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('group_user', function (Blueprint $table) use ($schema) {
$table->dropForeign(['user_id']);
$table->dropForeign(['group_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@@ -1,40 +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\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->create('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');
});
$schema->getConnection()->table('notifications')->chunkById(100, function ($notifications) use ($schema) {
foreach ($notifications 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->drop('notifications_from');
}
];

View File

@@ -9,55 +9,46 @@
* file that was distributed with this source code.
*/
use Carbon\Carbon;
use Illuminate\Database\Schema\Blueprint;
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->timestamp('read_at')->nullable();
$table->timestamp('deleted_at')->nullable();
$table->dateTime('read_at')->nullable();
});
$schema->getConnection()->table('notifications')
->where('is_read', 1)
->update(['read_at' => time()]);
$schema->getConnection()->table('notifications')
->where('is_deleted', 1)
->update(['deleted_at' => time()]);
->update(['read_at' => Carbon::now()]);
$schema->table('notifications', function (Blueprint $table) {
$table->dropColumn('is_read');
$table->dropColumn('is_deleted');
});
},
'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');
$table->boolean('is_deleted');
});
$schema->getConnection()->table('notifications')
->whereNotNull('read_at')
->update(['is_read' => 1]);
$schema->getConnection()->table('notifications')
->whereNotNull('deleted_at')
->update(['is_deleted' => 1]);
$schema->table('notifications', function (Blueprint $table) {
$table->dropColumn('read_at');
$table->dropColumn('deleted_at');
});
}
];

View File

@@ -0,0 +1,50 @@
<?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;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
// Delete rows with non-existent users so that we will be able to create
// foreign keys without any issues.
$schema->getConnection()
->table('notifications')
->whereNotExists(function ($query) {
$query->selectRaw(1)->from('users')->whereColumn('id', 'user_id');
})
->delete();
$schema->getConnection()
->table('notifications')
->whereNotExists(function ($query) {
$query->selectRaw(1)->from('users')->whereColumn('id', 'from_user_id');
})
->update(['from_user_id' => null]);
$schema->table('notifications', function (Blueprint $table) use ($schema) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('from_user_id')->references('id')->on('users')->onDelete('set null');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('notifications', function (Blueprint $table) use ($schema) {
$table->dropForeign(['user_id']);
$table->dropForeign(['from_user_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@@ -0,0 +1,41 @@
<?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;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
// Delete rows with non-existent users so that we will be able to create
// foreign keys without any issues.
$connection = $schema->getConnection();
$connection->table('password_tokens')
->whereNotExists(function ($query) {
$query->selectRaw(1)->from('users')->whereColumn('id', 'user_id');
})
->delete();
$schema->table('password_tokens', function (Blueprint $table) use ($schema) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('password_tokens', function (Blueprint $table) use ($schema) {
$table->dropForeign(['user_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@@ -0,0 +1,27 @@
<?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) {
// do this manually because dbal doesn't recognize timestamp columns
$connection = $schema->getConnection();
$prefix = $connection->getTablePrefix();
$connection->statement("ALTER TABLE {$prefix}password_tokens MODIFY created_at DATETIME");
},
'down' => function (Builder $schema) {
$connection = $schema->getConnection();
$prefix = $connection->getTablePrefix();
$connection->statement("ALTER TABLE {$prefix}password_tokens MODIFY created_at TIMESTAMP");
}
];

View File

@@ -1,42 +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\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->table('posts', function (Blueprint $table) {
$table->renameColumn('time', 'created_at');
$table->renameColumn('edit_time', 'edited_at');
$table->renameColumn('hide_time', 'hidden_at');
$table->renameColumn('edit_user_id', 'edited_user_id');
$table->renameColumn('hide_user_id', 'hidden_user_id');
$table->longText('content')->change();
});
},
'down' => function (Builder $schema) {
$schema->table('posts', function (Blueprint $table) {
$table->renameColumn('created_at', 'time');
$table->renameColumn('edited_at', 'edit_time');
$table->renameColumn('hidden_at', 'hide_time');
$table->renameColumn('edited_user_id', 'edit_user_id');
$table->renameColumn('edited_user_id', 'hidden_user_id');
});
$prefix = $schema->getConnection()->getTablePrefix();
$schema->getConnection()->statement('ALTER TABLE '.$prefix.'posts MODIFY content FULLTEXT');
}
];

View File

@@ -0,0 +1,20 @@
<?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;
return Migration::renameColumns('posts', [
'time' => 'created_at',
'edit_time' => 'edited_at',
'hide_time' => 'hidden_at',
'edit_user_id' => 'edited_user_id',
'hide_user_id' => 'hidden_user_id'
]);

View File

@@ -0,0 +1,54 @@
<?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\Query\Expression;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
// Set non-existent entity IDs to NULL so that we will be able to create
// foreign keys without any issues.
$connection = $schema->getConnection();
$selectId = function ($table, $column) use ($connection) {
return new Expression(
'('.$connection->table($table)->whereColumn('id', $column)->select('id')->toSql().')'
);
};
$connection->table('posts')->update([
'user_id' => $selectId('users', 'user_id'),
'edited_user_id' => $selectId('users', 'edited_user_id'),
'hidden_user_id' => $selectId('users', 'hidden_user_id'),
]);
$schema->table('posts', function (Blueprint $table) use ($schema) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('set null');
$table->foreign('edited_user_id')->references('id')->on('users')->onDelete('set null');
$table->foreign('hidden_user_id')->references('id')->on('users')->onDelete('set null');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('posts', function (Blueprint $table) use ($schema) {
$table->dropForeign(['user_id']);
$table->dropForeign(['discussion_id']);
$table->dropForeign(['edited_user_id']);
$table->dropForeign(['hidden_user_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@@ -1,26 +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\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$prefix = $schema->getConnection()->getTablePrefix();
// $schema->getConnection()->statement('ALTER TABLE '.$prefix.'settings MODIFY "value" LONGBLOB');
},
'down' => function (Builder $schema) {
$schema->table('posts', function (Blueprint $table) {
// $table->longText('value')->nullable()->change();
});
}
];

View File

@@ -0,0 +1,26 @@
<?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(
'post_user',
function (Blueprint $table) {
$table->integer('post_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->primary(['post_id', 'user_id']);
$table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
}
);

View File

@@ -1,29 +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\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->create('posts_users', function (Blueprint $table) {
$table->integer('post_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
},
'down' => function (Builder $schema) {
$schema->drop('posts_users');
}
];

View File

@@ -1,44 +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\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->table('users', function (Blueprint $table) {
$table->renameColumn('is_activated', 'is_email_confirmed');
$table->renameColumn('join_time', 'joined_at');
$table->renameColumn('last_seen_time', 'last_seen_at');
$table->renameColumn('discussions_count', 'discussion_count');
$table->renameColumn('comments_count', 'comment_count');
$table->renameColumn('read_time', 'marked_all_as_read_at');
$table->renameColumn('notifications_read_time', 'read_notifications_at');
$table->renameColumn('avatar_path', 'avatar_url');
$table->dropColumn('bio', 'preferences');
});
},
'down' => function (Builder $schema) {
$schema->table('users', function (Blueprint $table) {
$table->renameColumn('is_email_confirmed', 'is_activated');
$table->renameColumn('joined_at', 'join_time');
$table->renameColumn('last_seen_at', 'last_seen_time');
$table->renameColumn('discussion_count', 'discussions_count');
$table->renameColumn('comment_count', 'comments_count');
$table->renameColumn('marked_all_as_read_at', 'read_time');
$table->renameColumn('read_notifications_at', 'notifications_read_time');
$table->renameColumn('avatar_url', 'avatar_path');
$table->text('bio')->nullable();
$table->binary('preferences')->nullable();
});
}
];

View File

@@ -0,0 +1,23 @@
<?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;
return Migration::renameColumns('users', [
'is_activated' => 'is_email_confirmed',
'join_time' => 'joined_at',
'last_seen_time' => 'last_seen_at',
'discussions_count' => 'discussion_count',
'comments_count' => 'comment_count',
'read_time' => 'marked_all_as_read_at',
'notifications_read_time' => 'read_notifications_at',
'avatar_path' => 'avatar_url'
]);

View File

@@ -1,29 +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\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->create('users_users', function (Blueprint $table) {
$table->integer('user_id')->unsigned();
$table->integer('other_user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('posts')->onDelete('cascade');
$table->foreign('other_user_id')->references('id')->on('users')->onDelete('cascade');
});
},
'down' => function (Builder $schema) {
$schema->drop('users_users');
}
];

View File

@@ -0,0 +1,38 @@
<?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\Group\Group;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$db = $schema->getConnection();
$groups = [
[Group::ADMINISTRATOR_ID, 'Admin', 'Admins', '#B72A2A', 'fas fa-wrench'],
[Group::GUEST_ID, 'Guest', 'Guests', null, null],
[Group::MEMBER_ID, 'Member', 'Members', null, null],
[Group::MODERATOR_ID, 'Mod', 'Mods', '#80349E', 'fas fa-bolt']
];
foreach ($groups as $group) {
if ($db->table('groups')->where('id', $group[0])->exists()) {
continue;
}
$db->table('groups')->insert(array_combine(['id', 'name_singular', 'name_plural', 'color', 'icon'], $group));
}
},
'down' => function (Builder $schema) {
// do nothing so as to preserve user data
}
];

View File

@@ -0,0 +1,55 @@
<?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\Group\Group;
use Illuminate\Database\Schema\Builder;
$rows = [
// Guests can view the forum
['permission' => 'viewDiscussions', 'group_id' => Group::GUEST_ID],
// Members can create and reply to discussions, and view the user list
['permission' => 'startDiscussion', 'group_id' => Group::MEMBER_ID],
['permission' => 'discussion.reply', 'group_id' => Group::MEMBER_ID],
['permission' => 'viewUserList', 'group_id' => Group::MEMBER_ID],
// Moderators can edit + delete stuff
['permission' => 'discussion.hide', 'group_id' => Group::MODERATOR_ID],
['permission' => 'discussion.editPosts', 'group_id' => Group::MODERATOR_ID],
['permission' => 'discussion.hidePosts', 'group_id' => Group::MODERATOR_ID],
['permission' => 'discussion.rename', 'group_id' => Group::MODERATOR_ID],
['permission' => 'discussion.viewIpsPosts', 'group_id' => Group::MODERATOR_ID],
['permission' => 'user.viewLastSeenAt', 'group_id' => Group::MODERATOR_ID],
];
return [
'up' => function (Builder $schema) use ($rows) {
$db = $schema->getConnection();
foreach ($rows as $row) {
if ($db->table('groups')->where('id', $row['group_id'])->doesntExist()) {
continue;
}
if ($db->table('group_permission')->where($row)->doesntExist()) {
$db->table('group_permission')->insert($row);
}
}
},
'down' => function (Builder $schema) use ($rows) {
$db = $schema->getConnection();
foreach ($rows as $row) {
$db->table('group_permission')->where($row)->delete();
}
}
];

View File

@@ -0,0 +1,38 @@
<?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;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->table('users', function (Blueprint $table) use ($schema) {
$table->index('joined_at');
$table->index('last_seen_at');
$table->index('discussion_count');
$table->index('comment_count');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('users', function (Blueprint $table) use ($schema) {
$table->dropIndex(['joined_at']);
$table->dropIndex(['last_seen_at']);
$table->dropIndex(['discussion_count']);
$table->dropIndex(['comment_count']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@@ -0,0 +1,44 @@
<?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;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->table('discussions', function (Blueprint $table) use ($schema) {
$table->index('last_posted_at');
$table->index('last_posted_user_id');
$table->index('created_at');
$table->index('user_id');
$table->index('comment_count');
$table->index('participant_count');
$table->index('hidden_at');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('discussions', function (Blueprint $table) use ($schema) {
$table->dropIndex(['last_posted_at']);
$table->dropIndex(['last_posted_user_id']);
$table->dropIndex(['created_at']);
$table->dropIndex(['user_id']);
$table->dropIndex(['comment_count']);
$table->dropIndex(['participant_count']);
$table->dropIndex(['hidden_at']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@@ -9,21 +9,24 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->table('api_keys', function (Blueprint $table) {
$table->renameColumn('id', 'key');
$table->dropPrimary(['id', 'key']);
$schema->table('notifications', function (Blueprint $table) use ($schema) {
$table->index('user_id');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('api_keys', function (Blueprint $table) {
$table->renameColumn('key', 'id');
$table->primary('id');
$schema->table('notifications', function (Blueprint $table) use ($schema) {
$table->dropIndex(['user_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@@ -0,0 +1,36 @@
<?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;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->table('posts', function (Blueprint $table) use ($schema) {
$table->index(['discussion_id', 'number']);
$table->index(['discussion_id', 'created_at']);
$table->index(['user_id', 'created_at']);
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('posts', function (Blueprint $table) use ($schema) {
$table->dropIndex(['discussion_id', 'number']);
$table->dropIndex(['discussion_id', 'created_at']);
$table->dropIndex(['user_id', 'created_at']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@@ -0,0 +1,33 @@
<?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\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->table('registration_tokens', function (Blueprint $table) {
$table->string('provider');
$table->string('identifier');
$table->text('user_attributes')->nullable();
$table->text('payload')->nullable()->change();
});
},
'down' => function (Builder $schema) {
$schema->table('auth_tokens', function (Blueprint $table) {
$table->dropColumn('provider', 'identifier', 'user_attributes');
$table->string('payload', 150)->change();
});
}
];

View File

@@ -0,0 +1,28 @@
<?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(
'login_providers',
function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('user_id');
$table->string('provider', 100);
$table->string('identifier', 100);
$table->dateTime('created_at')->nullable();
$table->dateTime('last_login_at')->nullable();
$table->unique(['provider', 'identifier']);
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
}
);

View File

@@ -0,0 +1,34 @@
<?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) {
$groups = $schema->getConnection()->table('groups')
->where('icon', '<>', '')
->where('icon', 'NOT LIKE', '%fa-%')
->select('id', 'icon')
->cursor();
foreach ($groups as $group) {
$schema->getConnection()->table('groups')
->where('id', $group->id)
->update([
'icon' => 'fas fa-'.$group->icon
]);
}
},
'down' => function (Builder $schema) {
//
}
];