1
0
mirror of https://github.com/flarum/core.git synced 2025-02-24 11:13:40 +01:00
php-flarum/migrations/2015_02_24_000000_create_posts_table.php
Toby Zerner 322a84f516
Improve search performance (#1339)
* Improve fulltext gambit

* Only search in visible posts

This change relies on the `visibility-scoping` branch to be merged.

* Change posts table to use InnoDB engine

Doing a JOIN between an InnoDB table (discussions) and a MyISAM table
(posts) is very very (very) bad for performance. FULLTEXT indexes are
fully supported in InnoDB now, and it is a superior engine in every
other way, so there is no longer any reason to be using MyISAM.

* Use ::class

* Only search for comment posts

* Add fulltext index to discussions.title

* Fix migration not working if there is a table prefix

* Update frontend appearance

* Apply fixes from StyleCI

[ci skip] [skip ci]

* Show search result excerpts on mobile
2018-02-08 06:38:08 +10:30

48 lines
1.5 KiB
PHP

<?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;
// We need a full custom migration here, because we need to add the fulltext
// index for the content with a raw SQL statement after creating the table.
return [
'up' => function (Builder $schema) {
$schema->create('posts', function (Blueprint $table) {
$table->increments('id');
$table->integer('discussion_id')->unsigned();
$table->integer('number')->unsigned()->nullable();
$table->dateTime('time');
$table->integer('user_id')->unsigned()->nullable();
$table->string('type', 100)->nullable();
$table->text('content')->nullable();
$table->dateTime('edit_time')->nullable();
$table->integer('edit_user_id')->unsigned()->nullable();
$table->dateTime('hide_time')->nullable();
$table->integer('hide_user_id')->unsigned()->nullable();
$table->unique(['discussion_id', 'number']);
$table->engine = 'MyISAM';
});
$connection = $schema->getConnection();
$prefix = $connection->getTablePrefix();
$connection->statement('ALTER TABLE '.$prefix.'posts ADD FULLTEXT content (content)');
},
'down' => function (Builder $schema) {
$schema->drop('posts');
}
];