Skip to content

Commit

Permalink
Add additional checks to migrations to better support testing
Browse files Browse the repository at this point in the history
Credit to @scottbedard
  • Loading branch information
Luke Towers committed Jul 24, 2018
1 parent 961a296 commit 7d873bb
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 30 deletions.
10 changes: 6 additions & 4 deletions updates/users_add_deleted_at.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ public function up()

public function down()
{
Schema::table('users', function($table)
{
$table->dropColumn('deleted_at');
});
if (Schema::hasColumn('users', 'deleted_at')) {
Schema::table('users', function($table)
{
$table->dropColumn('deleted_at');
});
}
}
}
10 changes: 6 additions & 4 deletions updates/users_add_guest_flag.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ public function up()

public function down()
{
Schema::table('users', function($table)
{
$table->dropColumn('is_guest');
});
if (Schema::hasColumn('users', 'is_guest')) {
Schema::table('users', function($table)
{
$table->dropColumn('is_guest');
});
}
}
}
10 changes: 6 additions & 4 deletions updates/users_add_last_seen.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ public function up()

public function down()
{
Schema::table('users', function($table)
{
$table->dropColumn('last_seen');
});
if (Schema::hasColumn('users', 'last_seen')) {
Schema::table('users', function($table)
{
$table->dropColumn('last_seen');
});
}
}
}
11 changes: 6 additions & 5 deletions updates/users_add_login_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ public function up()

public function down()
{
Schema::table('users', function($table)
{
$table->dropColumn('login');
});
if (Schema::hasColumn('users', 'login')) {
Schema::table('users', function($table)
{
$table->dropColumn('login');
});
}
}

}
10 changes: 6 additions & 4 deletions updates/users_add_superuser_flag.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ public function up()

public function down()
{
Schema::table('users', function($table)
{
$table->dropColumn('is_superuser');
});
if (Schema::hasColumn('users', 'is_superuser')) {
Schema::table('users', function($table)
{
$table->dropColumn('is_superuser');
});
}
}
}
10 changes: 6 additions & 4 deletions updates/users_add_surname.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ public function up()

public function down()
{
Schema::table('users', function($table)
{
$table->dropColumn('surname');
});
if (Schema::hasColumn('users', 'surname')) {
Schema::table('users', function($table)
{
$table->dropColumn('surname');
});
}
}
}
11 changes: 6 additions & 5 deletions updates/users_rename_login_to_username.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ public function up()

public function down()
{
Schema::table('users', function($table)
{
$table->renameColumn('username', 'login');
});
if (Schema::hasColumn('users', 'login')) {
Schema::table('users', function($table)
{
$table->renameColumn('username', 'login');
});
}
}

}

0 comments on commit 7d873bb

Please sign in to comment.