remove ref counting, will be replaced by cleanup jobs or triggers

pull/26/head
Ondřej Hruška 7 years ago
parent e01c63cfa2
commit 9081b38425
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 16
      app/Models/Proposal.php
  2. 13
      app/Models/Revision.php
  3. 1
      app/Models/Row.php
  4. 17
      app/Models/Table.php
  5. 1
      database/migrations/2018_07_08_193500_create_rows_table.php
  6. 1
      database/migrations/2018_07_08_193600_create_revisions_table.php
  7. 7
      database/migrations/2018_07_08_194000_create_proposals_table.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()
{

@ -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()
{

@ -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

@ -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()
{

@ -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');
});
}

@ -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

@ -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');
});
}

Loading…
Cancel
Save