Skip to content

Commit

Permalink
Back in time fix FOR snipe#7145 for new installs on MySQL 8+
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Jun 12, 2019
1 parent 30904dd commit 2bfa05f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MigrationCartalystSentryInstallGroups extends Migration {
*/
public function up()
{
Schema::create('groups', function($table)
Schema::create('permission_groups', function($table)
{
$table->increments('id');
$table->string('name');
Expand All @@ -46,7 +46,7 @@ public function up()
*/
public function down()
{
Schema::drop('groups');
Schema::drop('permission_groups');
}

}
20 changes: 18 additions & 2 deletions database/migrations/2019_06_12_184327_rename_groups_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,21 @@ class RenameGroupsTable extends Migration
*/
public function up()
{
Schema::rename('groups', 'permission_groups');
// We check to see if this table exists before attempting the migration since
// upgraded installs would have this table, but new installs wouldn't.
// We had to change the name of the table in the older migrations
// to handle a MySQl 8+ compatibility issue related to reserved words.
// Without going back in time in migrations, this would fail since the groups table
// would never be allowed to be created in the first place on MySql 8+.
//
// So... if an upgrade, let's rename that table.
// If a new install, the migration was already changed, so the table isn't
// called that anymore and we can skip this migration.

if (Schema::hasTable('groups')) {
Schema::rename('groups', 'permission_groups');
}

}

/**
Expand All @@ -23,6 +37,8 @@ public function up()
*/
public function down()
{
Schema::rename('permission_groups', 'groups');
if (Schema::hasTable('permission_groups')) {
Schema::rename('permission_groups', 'groups');
}
}
}

0 comments on commit 2bfa05f

Please sign in to comment.