pull/26/head
Ondřej Hruška 6 years ago
parent f8c614162c
commit c75b25b89b
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 11
      database/migrations/2018_07_08_193500_create_rows_table.php
  2. 46
      database/migrations/2018_07_08_193600_create_revisions_table.php
  3. 44
      database/migrations/2018_07_08_193638_create_data_tables_table.php
  4. 45
      database/migrations/2018_07_08_193639_create_changesets_table.php
  5. 48
      database/migrations/2018_07_08_193700_create_tables_table.php
  6. 37
      database/migrations/2018_07_08_193730_create_table_revision_pivot_table.php
  7. 37
      database/migrations/2018_07_08_193800_create_revision_row_pivot_table.php
  8. 51
      database/migrations/2018_07_08_194000_create_proposals_table.php
  9. 37
      database/migrations/2018_07_08_194100_create_proposal_delete_row_pivot_table.php
  10. 37
      database/migrations/2018_07_08_194110_create_proposal_add_row_pivot_table.php
  11. 4
      database/migrations/2018_07_12_185431_create_table_comments_table.php
  12. 4
      database/migrations/2018_07_12_185840_create_table_favourites_table.php
  13. 4
      database/migrations/2018_07_12_190059_create_discussion_follows_table.php

@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateDataRowsTable extends Migration
class CreateRowsTable extends Migration
{
/**
* Run the migrations.
@ -13,13 +13,10 @@ class CreateDataRowsTable extends Migration
*/
public function up()
{
Schema::create('data_rows', function (Blueprint $table) {
Schema::create('rows', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('data_table_id')->index();
$table->unsignedInteger('refs'); // used for reference counting
$table->jsonb('data');
$table->foreign('data_table_id')->references('id')->on('data_tables')
->onDelete('cascade');
});
}
@ -30,6 +27,6 @@ class CreateDataRowsTable extends Migration
*/
public function down()
{
Schema::dropIfExists('data_rows');
Schema::dropIfExists('rows');
}
}

@ -0,0 +1,46 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateRevisionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('revisions', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->unsignedInteger('refs'); // used for reference counting
$table->unsignedInteger('author_id')->index();
$table->unsignedInteger('ancestor_id')->index()->nullable(); // parent revision
// a column that can be used as the primary key for a table; possibly a composite column if using a comma
$table->string('index_column')->nullable();
// author's note describing what has been changed
$table->text('note');
$table->foreign('author_id')->references('id')->on('users')
->onDelete('set null');
$table->foreign('ancestor_id')->references('id')->on('revisions')
->onDelete('set null');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('revisions');
}
}

@ -1,44 +0,0 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateDataTablesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('data_tables', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->unsignedInteger('owner_id');
$table->unsignedInteger('parent_table_id')->nullable(); // fork source
$table->unsignedInteger('revision'); // incremented with each applied changeset
$table->string('title')->index(); // indexable
$table->text('description');
$table->text('license');
$table->text('source_link');
$table->foreign('owner_id')->references('id')->on('users')
->onDelete('cascade');
$table->foreign('parent_table_id')->references('id')->on('data_tables')
->onDelete('set null');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('data_tables');
}
}

@ -1,45 +0,0 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateChangesetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('changesets', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->unsignedInteger('data_table_id')->index();
$table->unsignedInteger('target_revision');
$table->text('message');
$table->boolean('applied');
$table->unsignedInteger('author_id')->index()->nullable();
$table->jsonb('patch'); // incremental changeset including original row values so that it can be reversed
$table->foreign('data_table_id')->references('id')->on('data_tables')
->onDelete('cascade');
// 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');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('changesets');
}
}

@ -0,0 +1,48 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTablesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('tables', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->unsignedInteger('owner_id');
$table->unsignedInteger('ancestor_id')->index()->nullable();
$table->unsignedInteger('revision_id')->index(); // active revision
$table->string('title')->index(); // indexable
$table->text('description');
$table->text('license');
$table->text('source_link');
$table->foreign('owner_id')->references('id')->on('users')
->onDelete('restrict'); // user deleting their account deletes owned tables
// we block it with RESTRICT to ensure tables are deleted manually
$table->foreign('revision_id')->references('id')->on('revisions')
->onDelete('restrict');
$table->foreign('ancestor_id')->references('id')->on('tables')
->onDelete('set null'); // fork parent deletion must NOT delete child tables
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('tables');
}
}

@ -0,0 +1,37 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTableRevisionPivotTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('table_revision_pivot', function (Blueprint $table) {
$table->unsignedInteger('revision_id')->index();
$table->unsignedInteger('table_id')->index();
$table->foreign('revision_id')->references('id')->on('revisions')
->onDelete('cascade');
$table->foreign('table_id')->references('id')->on('tables')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('table_revision_pivot');
}
}

@ -0,0 +1,37 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateRevisionRowPivotTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('revision_row_pivot', function (Blueprint $table) {
$table->unsignedInteger('revision_id')->index();
$table->unsignedInteger('row_id')->index();
$table->foreign('revision_id')->references('id')->on('revisions')
->onDelete('cascade');
// ensure backward integrity constraint (but normally a row should not be deleted unless it's ref is 0)
$table->foreign('row_id')->references('id')->on('rows');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('revision_row_pivot');
}
}

@ -0,0 +1,51 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProposalsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('proposals', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
// note that a revision may be shared by multiple tables, thus a proposal may also apply to different tables
$table->unsignedInteger('table_id')->index(); // table this proposal was written for
$table->unsignedInteger('revision_id')->index(); // parent revision (applying it to a different revisions may cause conflicts)
$table->unsignedInteger('author_id')->index();
$table->text('note');
// block the delete - we must first decrement Row refs and then the proposals manually
$table->foreign('revision_id')->references('id')->on('revisions')
->onDelete('restrict');
// deleting the table must NOT delete the proposals, as they may be applicable to forks sharing the revision
$table->foreign('table_id')->references('id')->on('tables')
->onDelete('set null');
// block the delete - we must first decrement Row refs and then the proposals manually
$table->foreign('author_id')->references('id')->on('users')
->onDelete('restrict');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('proposals');
}
}

@ -0,0 +1,37 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProposalDeleteRowPivotTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('proposal_delete_row_pivot', function (Blueprint $table) {
$table->unsignedInteger('proposal_id')->index();
$table->unsignedInteger('row_id')->index();
$table->foreign('proposal_id')->references('id')->on('proposals')
->onDelete('cascade');
$table->foreign('row_id')->references('id')->on('rows')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('proposal_delete_row_pivot');
}
}

@ -0,0 +1,37 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProposalAddRowPivotTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('proposal_add_row_pivot', function (Blueprint $table) {
$table->unsignedInteger('proposal_id')->index();
$table->unsignedInteger('row_id')->index();
$table->foreign('proposal_id')->references('id')->on('proposals')
->onDelete('cascade');
$table->foreign('row_id')->references('id')->on('rows')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('proposal_add_row_pivot');
}
}

@ -18,10 +18,10 @@ class CreateTableCommentsTable extends Migration
$table->timestamps();
$table->unsignedInteger('ancestor_id')->index()->nullable();
$table->unsignedInteger('author_id')->index();
$table->unsignedInteger('data_table_id')->index();
$table->unsignedInteger('table_id')->index();
$table->text('message');
$table->foreign('data_table_id')->references('id')->on('data_tables')
$table->foreign('table_id')->references('id')->on('tables')
->onDelete('cascade');
$table->foreign('author_id')->references('id')->on('users')

@ -18,12 +18,12 @@ class CreateTableFavouritesTable extends Migration
$table->timestamps();
$table->unsignedInteger('user_id');
$table->unsignedInteger('data_table_id');
$table->unsignedInteger('table_id');
$table->foreign('user_id')->references('id')->on('users')
->onDelete('cascade');
$table->foreign('data_table_id')->references('id')->on('data_tables')
$table->foreign('table_id')->references('id')->on('tables')
->onDelete('cascade');
});
}

@ -17,12 +17,12 @@ class CreateDiscussionFollowsTable extends Migration
$table->increments('id');
$table->timestamps();
$table->unsignedInteger('user_id');
$table->unsignedInteger('data_table_id');
$table->unsignedInteger('table_id');
$table->foreign('user_id')->references('id')->on('users')
->onDelete('cascade');
$table->foreign('data_table_id')->references('id')->on('data_tables')
$table->foreign('table_id')->references('id')->on('tables')
->onDelete('cascade');
});
}

Loading…
Cancel
Save