datatable.directory codebase https://datatable.directory/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
datatable.directory/database/migrations/2018_07_08_194000_create_pr...

64 lines
2.1 KiB

6 years ago
<?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()->nullable(); // table this proposal was written for
6 years ago
$table->unsignedInteger('revision_id')->index(); // parent revision (applying it to a different revisions may cause conflicts)
$table->unsignedInteger('author_id')->index();
6 years ago
$table->text('note')->nullable();
6 years ago
$table->jsonb('changes'); // the actual meat of the changeset is stored here
6 years ago
$table->foreign('revision_id')->references('id')->on('revisions')
->onDelete('cascade'); // a proposal without the revision is useless
6 years ago
// 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');
// deleting author wipes their proposals
6 years ago
$table->foreign('author_id')->references('id')->on('users')
->onDelete('cascade');
6 years ago
});
// add FK to revisions to point to the source proposal
Schema::table('revisions', function (Blueprint $table) {
$table->foreign('proposal_id')->references('id')->on('proposals')
->onDelete('set null');
});
6 years ago
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// remove the FK
Schema::table('revisions', function (Blueprint $table) {
$table->dropForeign('revisions_proposal_id_foreign');
});
6 years ago
Schema::dropIfExists('proposals');
}
}