Skip to content

Commit fc5beeb

Browse files
committed
Bug: Could not execute some migrations due to table name changes
1 parent 0dc3a4d commit fc5beeb

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

src/Migrations/2018_04_11_181039_update_panichd_departments_rename.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,24 @@ public function up()
1616
{
1717
Schema::dropIfExists('ticketit_departments_persons');
1818

19-
Schema::rename('ticketit_departments', 'panichd_departments');
19+
if (Schema::hasTable('ticketit_departments')){
20+
Schema::rename('ticketit_departments', 'panichd_departments');
2021

21-
foreach (Department::whereNotNull('sub1')->get() as $dep){
22-
$dep->department = $dep->sub1;
23-
$dep->shortening = null;
24-
$dep->save();
22+
foreach (Department::whereNotNull('sub1')->get() as $dep){
23+
$dep->department = $dep->sub1;
24+
$dep->shortening = null;
25+
$dep->save();
26+
}
2527
}
2628

29+
if (Schema::hasColumn('panichd_departments', 'department')){
30+
Schema::table('panichd_departments', function (Blueprint $table) {
31+
$table->renameColumn('department', 'name');
32+
});
33+
}
2734
Schema::table('panichd_departments', function (Blueprint $table) {
28-
$table->renameColumn('department', 'name');
2935
$table->dropColumn('sub1');
30-
});
36+
});
3137
}
3238

3339
/**
@@ -37,7 +43,9 @@ public function up()
3743
*/
3844
public function down()
3945
{
40-
Schema::rename('panichd_departments', 'ticketit_departments');
46+
if (Schema::hasTable('panichd_departments')){
47+
Schema::rename('panichd_departments', 'ticketit_departments');
48+
}
4149

4250
Schema::table('ticketit_departments', function (Blueprint $table) {
4351
$table->renameColumn('name', 'department');

src/Migrations/2018_04_18_122824_update_rename_ticketit_settings_table.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class UpdateRenameTicketitSettingsTable extends Migration
1313
*/
1414
public function up()
1515
{
16-
Schema::rename('ticketit_settings', 'panichd_settings');
16+
if (Schema::hasTable('ticketit_settings')){
17+
Schema::rename('ticketit_settings', 'panichd_settings');
18+
}
1719
}
1820

1921
/**
@@ -23,6 +25,8 @@ public function up()
2325
*/
2426
public function down()
2527
{
26-
Schema::rename('panichd_settings', 'ticketit_settings');
28+
if (Schema::hasTable('panichd_settings')){
29+
Schema::rename('panichd_settings', 'ticketit_settings');
30+
}
2731
}
2832
}

0 commit comments

Comments
 (0)