simplified tables and added indexes

This commit is contained in:
2018-07-11 22:27:41 +02:00
parent be3164e997
commit 34e4ed5d9b
6 changed files with 41 additions and 29 deletions
@@ -16,41 +16,51 @@ class CreateDataTablesTable extends Migration
Schema::create('data_tables', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->unsignedInteger('owner_id');
$table->unsignedInteger('parent_data_table_id')->nullable();
$table->string('title');
$table->string('license');
$table->unsignedInteger('owner_id');
$table->unsignedInteger('forked_from_id')->nullable();
$table->unsignedInteger('revision'); // incremented with each applied changeset
$table->string('title'); // indexable
$table->string('keywords'); // indexable
$table->text('description');
$table->string('license'); // license name (indexable)
$table->mediumText('license_text'); // space for custom license text, if needed
$table->longText('content');
$table->foreign('owner_id')
->references('id')->on('users')
->onDelete('cascade');
$table->foreign('owner_id')
->references('id')->on('users')
->onDelete('cascade');
$table->foreign('parent_data_table_id')
->references('id')->on('data_tables')
->onDelete('set null');
$table->foreign('forked_from_id')
->references('id')->on('data_tables')
->onDelete('set null');
$table->index('title'); // for text search
$table->index('keywords'); // for text search
$table->index('owner_id');
});
Schema::create('table_revisions', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->boolean('approved');
$table->unsignedInteger('data_table_id');
$table->unsignedInteger('parent_revision_id')->nullable();
$table->unsignedInteger('author_id')->nullable();
$table->longText('content');
Schema::create('changesets', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->unsignedInteger('data_table_id');
$table->unsignedInteger('target_revision');
$table->boolean('applied');
$table->unsignedInteger('author_id')->nullable();
$table->longText('content'); // incremental changeset including original row values so that it can be reversed
$table->foreign('data_table_id')
->references('id')->on('data_tables')
->onDelete('cascade');
$table->foreign('data_table_id')
->references('id')->on('data_tables')
->onDelete('cascade');
$table->foreign('parent_revision_id')
->references('id')->on('table_revisions')
->onDelete('set null');
// Deleting a user should not delete their applied patches, as that would break history.
// We set the author to null and unmerged patches may be cleaned manually or by a separate query.
$table->foreign('author_id')
->references('id')->on('users')
->onDelete('set null');
$table->foreign('author_id')
->references('id')->on('users')
->onDelete('set null');
});
$table->index('author_id');
$table->index('data_table_id');
});
}
/**
@@ -60,7 +70,7 @@ class CreateDataTablesTable extends Migration
*/
public function down()
{
Schema::dropIfExists('table_revisions');
Schema::dropIfExists('changesets');
Schema::dropIfExists('data_tables');
}
}
@@ -1,41 +0,0 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTableCommentsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('table_comments', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->unsignedInteger('data_table_id');
$table->unsignedInteger('author_id');
$table->foreign('data_table_id')
->references('id')->on('data_tables')
->onDelete('cascade');
$table->foreign('author_id')
->references('id')->on('users')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('table_comments');
}
}
@@ -1,41 +0,0 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUserFollowsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('user_follows', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->unsignedInteger('user_id');
$table->unsignedInteger('target_user_id');
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');
$table->foreign('target_user_id')
->references('id')->on('users')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('user_follows');
}
}
@@ -1,41 +0,0 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateDiscussionFollowsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('discussion_follows', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->unsignedInteger('user_id');
$table->unsignedInteger('data_table_id');
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');
$table->foreign('data_table_id')
->references('id')->on('data_tables')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('discussion_follows');
}
}
@@ -1,42 +0,0 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTableFavouritesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('table_favourites', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->unsignedInteger('user_id');
$table->unsignedInteger('data_table_id');
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');
$table->foreign('data_table_id')
->references('id')->on('data_tables')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('table_favourites');
}
}
@@ -24,6 +24,8 @@ class CreateOauthIdentitiesTable extends Migration
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');
$table->index('user_id');
});
}