diff --git a/app/Models/Proposal.php b/app/Models/Proposal.php index f47ddb9..877f881 100644 --- a/app/Models/Proposal.php +++ b/app/Models/Proposal.php @@ -25,22 +25,6 @@ class Proposal extends Model use Reportable; protected $guarded = []; - protected static function boot() - { - parent::boot(); - - static::deleting(function(Proposal $self) { - $self->reportsOf()->delete(); - - // update refcounts - $rev = $self->revision; - $rev->decrement('refs'); - - // Delete the revision if it has no other refs (manually, to update row refs) - if ($rev->refs <= 0) $rev->delete(); - }); - } - /** Authoring user */ public function author() { diff --git a/app/Models/Revision.php b/app/Models/Revision.php index 0287a05..fbf3321 100644 --- a/app/Models/Revision.php +++ b/app/Models/Revision.php @@ -12,7 +12,6 @@ use Riesjart\Relaquent\Model\Concerns\HasRelaquentRelationships; * @property int $id * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at - * @property int $refs * @property int $ancestor_id * @property string $note * @property object $columns @@ -26,18 +25,6 @@ class Revision extends Model use HasRelaquentRelationships; protected $guarded = []; - protected static function boot() - { - parent::boot(); - - static::deleting(function(Revision $self) { - // update refcounts - $self->rows()->decrement('refs'); - - $self->rows()->where('refs', '<=', 0)->delete(); - }); - } - /** Included rows */ public function rows() { diff --git a/app/Models/Row.php b/app/Models/Row.php index f7c3214..0b16ded 100644 --- a/app/Models/Row.php +++ b/app/Models/Row.php @@ -8,7 +8,6 @@ use Illuminate\Database\Eloquent\Model; * Row in a data table * * @property int $id - * @property int $refs * @property string $data - JSONB */ class Row extends Model diff --git a/app/Models/Table.php b/app/Models/Table.php index c3c229a..de6ebd3 100644 --- a/app/Models/Table.php +++ b/app/Models/Table.php @@ -35,23 +35,6 @@ class Table extends Model use Reportable; protected $guarded = []; - protected static function boot() - { - parent::boot(); - - static::deleting(function(Table $self) { - // update revision refcounts - $self->revisions()->decrement('refs'); - - $self->reportsOf()->delete(); - - // delete revisions with zero refs (manually, to properly cascade to rows) - foreach ($self->revisions()->where('refs', '<=', 0)->get() as $rev) { - $rev->delete(); - } - }); - } - /** Owning user */ public function owner() { diff --git a/database/migrations/2018_07_08_193500_create_rows_table.php b/database/migrations/2018_07_08_193500_create_rows_table.php index 7c40e13..5690a42 100644 --- a/database/migrations/2018_07_08_193500_create_rows_table.php +++ b/database/migrations/2018_07_08_193500_create_rows_table.php @@ -15,7 +15,6 @@ class CreateRowsTable extends Migration { Schema::create('rows', function (Blueprint $table) { $table->increments('id'); - $table->unsignedInteger('refs'); // used for reference counting $table->jsonb('data'); }); } 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 b5170fb..3dc32f1 100644 --- a/database/migrations/2018_07_08_193600_create_revisions_table.php +++ b/database/migrations/2018_07_08_193600_create_revisions_table.php @@ -16,7 +16,6 @@ class CreateRevisionsTable extends Migration Schema::create('revisions', function (Blueprint $table) { $table->increments('id'); $table->timestamps(); - $table->unsignedInteger('refs'); // used for reference counting $table->unsignedInteger('ancestor_id')->index()->nullable(); // parent revision // columns specification 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 7138357..73e89d2 100644 --- a/database/migrations/2018_07_08_194000_create_proposals_table.php +++ b/database/migrations/2018_07_08_194000_create_proposals_table.php @@ -27,17 +27,16 @@ class CreateProposalsTable extends Migration $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'); + ->onDelete('cascade'); // a proposal without the revision is useless // 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 + // deleting author wipes their proposals $table->foreign('author_id')->references('id')->on('users') - ->onDelete('restrict'); + ->onDelete('cascade'); }); }