From 8efa08b1ccf73d47ca6c52a348dad1596be7f7fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sat, 14 Jul 2018 14:41:59 +0200 Subject: [PATCH] got rid of proposal-column references --- app/Models/Proposal.php | 23 ------------ ...18_07_08_193600_create_revisions_table.php | 4 +- ...18_07_08_194000_create_proposals_table.php | 2 + ...create_proposal_remove_row_pivot_table.php | 37 ------------------- ...10_create_proposal_add_row_pivot_table.php | 37 ------------------- 5 files changed, 4 insertions(+), 99 deletions(-) delete mode 100644 database/migrations/2018_07_08_194100_create_proposal_remove_row_pivot_table.php delete mode 100644 database/migrations/2018_07_08_194110_create_proposal_add_row_pivot_table.php diff --git a/app/Models/Proposal.php b/app/Models/Proposal.php index bbcd675..67027b5 100644 --- a/app/Models/Proposal.php +++ b/app/Models/Proposal.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() { diff --git a/database/migrations/2018_07_08_193600_create_revisions_table.php b/database/migrations/2018_07_08_193600_create_revisions_table.php index 2f3d3bd..26edba8 100644 --- a/database/migrations/2018_07_08_193600_create_revisions_table.php +++ b/database/migrations/2018_07_08_193600_create_revisions_table.php @@ -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'); diff --git a/database/migrations/2018_07_08_194000_create_proposals_table.php b/database/migrations/2018_07_08_194000_create_proposals_table.php index 3670d49..8cf2f9f 100644 --- a/database/migrations/2018_07_08_194000_create_proposals_table.php +++ b/database/migrations/2018_07_08_194000_create_proposals_table.php @@ -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'); diff --git a/database/migrations/2018_07_08_194100_create_proposal_remove_row_pivot_table.php b/database/migrations/2018_07_08_194100_create_proposal_remove_row_pivot_table.php deleted file mode 100644 index 64ad5ac..0000000 --- a/database/migrations/2018_07_08_194100_create_proposal_remove_row_pivot_table.php +++ /dev/null @@ -1,37 +0,0 @@ -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'); - } -} diff --git a/database/migrations/2018_07_08_194110_create_proposal_add_row_pivot_table.php b/database/migrations/2018_07_08_194110_create_proposal_add_row_pivot_table.php deleted file mode 100644 index 60e1bd2..0000000 --- a/database/migrations/2018_07_08_194110_create_proposal_add_row_pivot_table.php +++ /dev/null @@ -1,37 +0,0 @@ -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'); - } -}