increments('id'); $table->timestamps(); $table->unsignedInteger('owner_id'); $table->unsignedInteger('ancestor_id')->index()->nullable(); $table->unsignedInteger('revision_id')->index(); // active revision $table->string('name')->index(); // indexable $table->string('title')->index(); // indexable $table->text('description')->nullable(); $table->text('license')->nullable(); $table->text('origin')->nullable(); $table->foreign('owner_id')->references('id')->on('users') ->onDelete('restrict'); // user deleting their account deletes owned tables // we block it with RESTRICT to ensure tables are deleted manually $table->foreign('revision_id')->references('id')->on('revisions') ->onDelete('restrict'); $table->foreign('ancestor_id')->references('id')->on('tables') ->onDelete('set null'); // fork parent deletion must NOT delete child tables }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('tables'); } }