got rid of proposal-column references

pull/26/head
Ondřej Hruška 6 years ago
parent 7493d3e176
commit 8efa08b1cc
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 23
      app/Models/Proposal.php
  2. 4
      database/migrations/2018_07_08_193600_create_revisions_table.php
  3. 2
      database/migrations/2018_07_08_194000_create_proposals_table.php
  4. 37
      database/migrations/2018_07_08_194100_create_proposal_remove_row_pivot_table.php
  5. 37
      database/migrations/2018_07_08_194110_create_proposal_add_row_pivot_table.php

@ -18,29 +18,6 @@ class Proposal extends Model
use Reportable;
use NotificationContext;
protected static function boot()
{
parent::boot();
static::deleting(function(Proposal $self) {
// update refcounts
$self->addedRows()->decrement('refs');
$self->removedRows()->decrement('refs');
});
}
/** Added rows */
public function addedRows()
{
return $this->belongsToMany(Row::class, 'proposal_add_row_pivot');
}
/** Removed rows */
public function removedRows()
{
return $this->belongsToMany(Row::class, 'proposal_remove_row_pivot');
}
/** Authoring user */
public function author()
{

@ -19,8 +19,8 @@ class CreateRevisionsTable extends Migration
$table->unsignedInteger('refs'); // used for reference counting
$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();
// 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');
// author's note describing what has been changed
$table->text('note');

@ -25,6 +25,8 @@ class CreateProposalsTable extends Migration
$table->text('note');
$table->jsonb('changes'); // the actual meat of the changeset is stored here
// block the delete - we must first decrement Row refs and then the proposals manually
$table->foreign('revision_id')->references('id')->on('revisions')
->onDelete('restrict');

@ -1,37 +0,0 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProposalRemoveRowPivotTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('proposal_remove_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_remove_row_pivot');
}
}

@ -1,37 +0,0 @@
<?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…
Cancel
Save