reworked migrations AGAIN and added relations to models
This commit is contained in:
@@ -17,49 +17,19 @@ class CreateDataTablesTable extends Migration
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->unsignedInteger('owner_id');
|
||||
$table->unsignedInteger('forked_from_id')->nullable();
|
||||
$table->unsignedInteger('precursor_id')->nullable(); // fork source
|
||||
$table->unsignedInteger('revision'); // incremented with each applied changeset
|
||||
$table->string('title'); // indexable
|
||||
$table->string('keywords'); // indexable
|
||||
$table->string('title')->index(); // indexable
|
||||
$table->text('description');
|
||||
$table->string('license'); // license name (indexable)
|
||||
$table->mediumText('license_text'); // space for custom license text, if needed
|
||||
$table->text('license');
|
||||
$table->text('source_link');
|
||||
$table->longText('content');
|
||||
|
||||
$table->foreign('owner_id')
|
||||
->references('id')->on('users')
|
||||
$table->foreign('owner_id')->references('id')->on('users')
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->foreign('forked_from_id')
|
||||
->references('id')->on('data_tables')
|
||||
$table->foreign('precursor_id')->references('id')->on('data_tables')
|
||||
->onDelete('set null');
|
||||
|
||||
$table->index('title'); // for text search
|
||||
$table->index('keywords'); // for text search
|
||||
$table->index('owner_id');
|
||||
});
|
||||
|
||||
Schema::create('changesets', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->unsignedInteger('data_table_id');
|
||||
$table->unsignedInteger('target_revision');
|
||||
$table->boolean('applied');
|
||||
$table->unsignedInteger('author_id')->nullable();
|
||||
$table->longText('content'); // incremental changeset including original row values so that it can be reversed
|
||||
|
||||
$table->foreign('data_table_id')
|
||||
->references('id')->on('data_tables')
|
||||
->onDelete('cascade');
|
||||
|
||||
// Deleting a user should not delete their applied patches, as that would break history.
|
||||
// We set the author to null and unmerged patches may be cleaned manually or by a separate query.
|
||||
$table->foreign('author_id')
|
||||
->references('id')->on('users')
|
||||
->onDelete('set null');
|
||||
|
||||
$table->index('author_id');
|
||||
$table->index('data_table_id');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -70,7 +40,6 @@ class CreateDataTablesTable extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('changesets');
|
||||
Schema::dropIfExists('data_tables');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateChangesetsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('changesets', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamp('created_at');
|
||||
$table->unsignedInteger('data_table_id')->index();
|
||||
$table->unsignedInteger('target_revision');
|
||||
$table->boolean('applied');
|
||||
$table->unsignedInteger('author_id')->index()->nullable();
|
||||
$table->longText('content'); // incremental changeset including original row values so that it can be reversed
|
||||
|
||||
$table->foreign('data_table_id')->references('id')->on('data_tables')
|
||||
->onDelete('cascade');
|
||||
|
||||
// Deleting a user should not delete their applied patches, as that would break history.
|
||||
// We set the author to null and unmerged patches may be cleaned manually or by a separate query.
|
||||
$table->foreign('author_id')->references('id')->on('users')
|
||||
->onDelete('set null');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('changesets');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateDataRowsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('data_rows', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->unsignedInteger('data_table_id')->index();
|
||||
$table->longtext('data');
|
||||
|
||||
$table->foreign('data_table_id')->references('id')->on('data_tables')
|
||||
->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('data_rows');
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ class CreateOauthIdentitiesTable extends Migration
|
||||
Schema::create('oauth_identities', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->unsignedInteger('user_id');
|
||||
$table->unsignedInteger('user_id')->index();
|
||||
$table->string('provider_user_id');
|
||||
$table->string('provider');
|
||||
$table->string('access_token');
|
||||
@@ -24,8 +24,6 @@ class CreateOauthIdentitiesTable extends Migration
|
||||
$table->foreign('user_id')
|
||||
->references('id')->on('users')
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->index('user_id');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user