parent
f8c614162c
commit
c75b25b89b
@ -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'); |
||||
} |
||||
} |
Loading…
Reference in new issue