|  |  | @ -17,39 +17,49 @@ class CreateDataTablesTable extends Migration | 
			
		
	
		
		
			
				
					
					|  |  |  |             $table->increments('id'); |  |  |  |             $table->increments('id'); | 
			
		
	
		
		
			
				
					
					|  |  |  |             $table->timestamps(); |  |  |  |             $table->timestamps(); | 
			
		
	
		
		
			
				
					
					|  |  |  |             $table->unsignedInteger('owner_id'); |  |  |  |             $table->unsignedInteger('owner_id'); | 
			
		
	
		
		
			
				
					
					|  |  |  | 	        $table->unsignedInteger('parent_data_table_id')->nullable(); |  |  |  |             $table->unsignedInteger('forked_from_id')->nullable(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 	        $table->string('title'); |  |  |  |             $table->unsignedInteger('revision'); // incremented with each applied changeset | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 	        $table->string('license'); |  |  |  |             $table->string('title'); // indexable | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             $table->string('keywords'); // indexable | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             $table->text('description'); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             $table->string('license'); // license name (indexable) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             $table->mediumText('license_text'); // space for custom license text, if needed | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             $table->longText('content'); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             $table->foreign('owner_id') |  |  |  |             $table->foreign('owner_id') | 
			
		
	
		
		
			
				
					
					|  |  |  |                 ->references('id')->on('users') |  |  |  |                 ->references('id')->on('users') | 
			
		
	
		
		
			
				
					
					|  |  |  |                 ->onDelete('cascade'); |  |  |  |                 ->onDelete('cascade'); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	        $table->foreign('parent_data_table_id') |  |  |  |             $table->foreign('forked_from_id') | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 ->references('id')->on('data_tables') |  |  |  |                 ->references('id')->on('data_tables') | 
			
		
	
		
		
			
				
					
					|  |  |  |                 ->onDelete('set null'); |  |  |  |                 ->onDelete('set null'); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             $table->index('title'); // for text search | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             $table->index('keywords'); // for text search | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             $table->index('owner_id'); | 
			
		
	
		
		
			
				
					
					|  |  |  |         }); |  |  |  |         }); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	    Schema::create('table_revisions', function (Blueprint $table) { |  |  |  |         Schema::create('changesets', function (Blueprint $table) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             $table->increments('id'); |  |  |  |             $table->increments('id'); | 
			
		
	
		
		
			
				
					
					|  |  |  |             $table->timestamps(); |  |  |  |             $table->timestamps(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		    $table->boolean('approved'); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             $table->unsignedInteger('data_table_id'); |  |  |  |             $table->unsignedInteger('data_table_id'); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		    $table->unsignedInteger('parent_revision_id')->nullable(); |  |  |  |             $table->unsignedInteger('target_revision'); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             $table->boolean('applied'); | 
			
		
	
		
		
			
				
					
					|  |  |  |             $table->unsignedInteger('author_id')->nullable(); |  |  |  |             $table->unsignedInteger('author_id')->nullable(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		    $table->longText('content'); |  |  |  |             $table->longText('content'); // incremental changeset including original row values so that it can be reversed | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             $table->foreign('data_table_id') |  |  |  |             $table->foreign('data_table_id') | 
			
		
	
		
		
			
				
					
					|  |  |  |                 ->references('id')->on('data_tables') |  |  |  |                 ->references('id')->on('data_tables') | 
			
		
	
		
		
			
				
					
					|  |  |  |                 ->onDelete('cascade'); |  |  |  |                 ->onDelete('cascade'); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		    $table->foreign('parent_revision_id') |  |  |  |             // Deleting a user should not delete their applied patches, as that would break history. | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			    ->references('id')->on('table_revisions') |  |  |  |             // We set the author to null and unmerged patches may be cleaned manually or by a separate query. | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			    ->onDelete('set null'); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             $table->foreign('author_id') |  |  |  |             $table->foreign('author_id') | 
			
		
	
		
		
			
				
					
					|  |  |  |                 ->references('id')->on('users') |  |  |  |                 ->references('id')->on('users') | 
			
		
	
		
		
			
				
					
					|  |  |  |                 ->onDelete('set null'); |  |  |  |                 ->onDelete('set null'); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             $table->index('author_id'); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             $table->index('data_table_id'); | 
			
		
	
		
		
			
				
					
					|  |  |  |         }); |  |  |  |         }); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -60,7 +70,7 @@ class CreateDataTablesTable extends Migration | 
			
		
	
		
		
			
				
					
					|  |  |  |      */ |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public function down() |  |  |  |     public function down() | 
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |     { | 
			
		
	
		
		
			
				
					
					|  |  |  | 	    Schema::dropIfExists('table_revisions'); |  |  |  |         Schema::dropIfExists('changesets'); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         Schema::dropIfExists('data_tables'); |  |  |  |         Schema::dropIfExists('data_tables'); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |