2017-04-20 21:58:54 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
2021-06-26 17:23:15 +02:00
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
2017-04-20 21:58:54 +02:00
|
|
|
|
2023-02-06 17:58:29 +01:00
|
|
|
return new class extends Migration
|
2017-04-20 21:58:54 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the migrations.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function up()
|
|
|
|
{
|
|
|
|
Schema::table('pages', function (Blueprint $table) {
|
|
|
|
$table->integer('revision_count');
|
|
|
|
});
|
|
|
|
Schema::table('page_revisions', function (Blueprint $table) {
|
|
|
|
$table->integer('revision_number');
|
|
|
|
$table->index('revision_number');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Update revision count
|
|
|
|
$pTable = DB::getTablePrefix() . 'pages';
|
|
|
|
$rTable = DB::getTablePrefix() . 'page_revisions';
|
2023-02-08 14:20:00 +01:00
|
|
|
DB::statement("UPDATE {$pTable} SET {$pTable}.revision_count=(SELECT count(*) FROM {$rTable} WHERE {$rTable}.page_id={$pTable}.id)");
|
2017-04-20 21:58:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reverse the migrations.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function down()
|
|
|
|
{
|
|
|
|
Schema::table('pages', function (Blueprint $table) {
|
|
|
|
$table->dropColumn('revision_count');
|
|
|
|
});
|
|
|
|
Schema::table('page_revisions', function (Blueprint $table) {
|
|
|
|
$table->dropColumn('revision_number');
|
|
|
|
});
|
|
|
|
}
|
2023-02-06 17:58:29 +01:00
|
|
|
};
|