-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lasteditor => user_id to match Spacialist
Signed-off-by: Vinzenz Rosenkranz <vinzenz.rosenkranz@uni-tuebingen.de>
- Loading branch information
Showing
10 changed files
with
107 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
database/migrations/2021_07_21_070235_replace_lasteditor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
use App\User; | ||
use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class ReplaceLasteditor extends Migration | ||
{ | ||
private $withLasteditor = [ | ||
'th_concept_master', | ||
'th_concept_label_master', | ||
'th_language', | ||
]; | ||
|
||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
foreach ($this->withLasteditor as $le) { | ||
// Skip tables which already updated by Spacialist | ||
if(Schema::hasColumn($le, 'user_id')) continue; | ||
|
||
$entries = $this->getElements($le); | ||
|
||
Schema::table($le, function (Blueprint $table) { | ||
$table->dropColumn('lasteditor'); | ||
$table->integer('user_id')->nullable(); | ||
}); | ||
|
||
foreach ($entries as $e) { | ||
try { | ||
$user = User::where('name', $e->lasteditor)->firstOrFail(); | ||
} catch (ModelNotFoundException $exc) { | ||
$user = User::orderBy('id')->first(); | ||
} | ||
$e->user_id = $user->id; | ||
$e->save(); | ||
} | ||
|
||
Schema::table($le, function (Blueprint $table) { | ||
$table->integer('user_id')->nullable(false)->change(); | ||
|
||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
// | ||
} | ||
|
||
private function getElements($tableName) | ||
{ | ||
switch ($tableName) { | ||
case 'th_concept_master': | ||
return \App\ThConceptSandbox::all(); | ||
case 'th_concept_label_master': | ||
return \App\ThConceptLabelSandbox::all(); | ||
case 'th_language': | ||
return \App\ThLanguage::all(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters