reverts #41688c7

This commit is contained in:
Daniël Klabbers 2019-01-15 20:39:38 +01:00
parent f0d626aaa7
commit d56ea1ef07
15 changed files with 4 additions and 105 deletions

View File

@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
@ -26,16 +25,12 @@ return [
$schema->table('access_tokens', function (Blueprint $table) use ($schema) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('access_tokens', function (Blueprint $table) use ($schema) {
$table->dropForeign(['user_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@ -9,21 +9,18 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->table('api_keys', function (Blueprint $table) use ($schema) {
$schema->table('api_keys', function (Blueprint $table) {
$table->dropPrimary(['id']);
$table->renameColumn('id', 'key');
$table->unique('key');
Migration::fixIndexNames($schema, $table);
});
$schema->table('api_keys', function (Blueprint $table) use ($schema) {
$schema->table('api_keys', function (Blueprint $table) {
$table->increments('id');
$table->string('allowed_ips')->nullable();
$table->string('scopes')->nullable();
@ -32,25 +29,19 @@ return [
$table->dateTime('last_activity_at')->nullable();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('api_keys', function (Blueprint $table) use ($schema) {
$schema->table('api_keys', function (Blueprint $table) {
$table->dropForeign(['user_id']);
$table->dropColumn('id', 'allowed_ips', 'user_id', 'scopes', 'created_at');
Migration::fixIndexNames($schema, $table);
});
$schema->table('api_keys', function (Blueprint $table) use ($schema) {
$schema->table('api_keys', function (Blueprint $table) {
$table->dropUnique(['key']);
$table->renameColumn('key', 'id');
$table->primary('id');
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Query\Expression;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
@ -40,8 +39,6 @@ return [
$table->foreign('hidden_user_id')->references('id')->on('users')->onDelete('set null');
$table->foreign('first_post_id')->references('id')->on('posts')->onDelete('set null');
$table->foreign('last_post_id')->references('id')->on('posts')->onDelete('set null');
Migration::fixIndexNames($schema, $table);
});
},
@ -52,8 +49,6 @@ return [
$table->dropForeign(['hidden_user_id']);
$table->dropForeign(['first_post_id']);
$table->dropForeign(['last_post_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
@ -30,8 +29,6 @@ return [
$schema->table('discussion_user', function (Blueprint $table) use ($schema) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('discussion_id')->references('id')->on('discussions')->onDelete('cascade');
Migration::fixIndexNames($schema, $table);
});
},
@ -39,8 +36,6 @@ return [
$schema->table('discussion_user', function (Blueprint $table) use ($schema) {
$table->dropForeign(['user_id']);
$table->dropForeign(['discussion_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
@ -26,16 +25,12 @@ return [
$schema->table('email_tokens', function (Blueprint $table) use ($schema) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('email_tokens', function (Blueprint $table) use ($schema) {
$table->dropForeign(['user_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
@ -26,16 +25,12 @@ return [
$schema->table('group_permission', function (Blueprint $table) use ($schema) {
$table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('group_permission', function (Blueprint $table) use ($schema) {
$table->dropForeign(['group_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
@ -30,8 +29,6 @@ return [
$schema->table('group_user', function (Blueprint $table) use ($schema) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade');
Migration::fixIndexNames($schema, $table);
});
},
@ -39,8 +36,6 @@ return [
$schema->table('group_user', function (Blueprint $table) use ($schema) {
$table->dropForeign(['user_id']);
$table->dropForeign(['group_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
@ -34,8 +33,6 @@ return [
$schema->table('notifications', function (Blueprint $table) use ($schema) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('from_user_id')->references('id')->on('users')->onDelete('set null');
Migration::fixIndexNames($schema, $table);
});
},
@ -43,8 +40,6 @@ return [
$schema->table('notifications', function (Blueprint $table) use ($schema) {
$table->dropForeign(['user_id']);
$table->dropForeign(['from_user_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
@ -26,16 +25,12 @@ return [
$schema->table('password_tokens', function (Blueprint $table) use ($schema) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('password_tokens', function (Blueprint $table) use ($schema) {
$table->dropForeign(['user_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Query\Expression;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
@ -36,8 +35,6 @@ return [
$table->foreign('user_id')->references('id')->on('users')->onDelete('set null');
$table->foreign('edited_user_id')->references('id')->on('users')->onDelete('set null');
$table->foreign('hidden_user_id')->references('id')->on('users')->onDelete('set null');
Migration::fixIndexNames($schema, $table);
});
},
@ -47,8 +44,6 @@ return [
$table->dropForeign(['discussion_id']);
$table->dropForeign(['edited_user_id']);
$table->dropForeign(['hidden_user_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
@ -20,8 +19,6 @@ return [
$table->index('last_seen_at');
$table->index('discussion_count');
$table->index('comment_count');
Migration::fixIndexNames($schema, $table);
});
},
@ -31,8 +28,6 @@ return [
$table->dropIndex(['last_seen_at']);
$table->dropIndex(['discussion_count']);
$table->dropIndex(['comment_count']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
@ -23,8 +22,6 @@ return [
$table->index('comment_count');
$table->index('participant_count');
$table->index('hidden_at');
Migration::fixIndexNames($schema, $table);
});
},
@ -37,8 +34,6 @@ return [
$table->dropIndex(['comment_count']);
$table->dropIndex(['participant_count']);
$table->dropIndex(['hidden_at']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
@ -17,16 +16,12 @@ return [
'up' => function (Builder $schema) {
$schema->table('notifications', function (Blueprint $table) use ($schema) {
$table->index('user_id');
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) {
$schema->table('notifications', function (Blueprint $table) use ($schema) {
$table->dropIndex(['user_id']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/
use Flarum\Database\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
@ -19,8 +18,6 @@ return [
$table->index(['discussion_id', 'number']);
$table->index(['discussion_id', 'created_at']);
$table->index(['user_id', 'created_at']);
Migration::fixIndexNames($schema, $table);
});
},
@ -29,8 +26,6 @@ return [
$table->dropIndex(['discussion_id', 'number']);
$table->dropIndex(['discussion_id', 'created_at']);
$table->dropIndex(['user_id', 'created_at']);
Migration::fixIndexNames($schema, $table);
});
}
];

View File

@ -31,8 +31,6 @@ abstract class Migration
'up' => function (Builder $schema) use ($name, $definition) {
$schema->create($name, function (Blueprint $table) use ($schema, $definition) {
$definition($table);
static::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) use ($name) {
@ -68,8 +66,6 @@ abstract class Migration
$type = array_shift($options);
$table->addColumn($type, $columnName, $options);
}
Migration::fixIndexNames($schema, $table);
});
},
'down' => function (Builder $schema) use ($tableName, $columnDefinitions) {
@ -193,27 +189,4 @@ abstract class Migration
}
];
}
/**
* Add a prefix to index names on the given table blueprint.
*
* Laravel 5.5 doesn't automatically add the table prefix to index
* names, but this has been fixed in 5.7. We will manually fix the
* names for now, and we can remove this when we upgrade to 5.7.
*/
public static function fixIndexNames(Builder $schema, Blueprint $table)
{
$indexCommands = [
'unique', 'index', 'spatialIndex', 'foreign',
'dropUnique', 'dropIndex', 'dropSpatialIndex', 'dropForeign'
];
$prefix = $schema->getConnection()->getTablePrefix();
foreach ($table->getCommands() as $command) {
if (in_array($command->name, $indexCommands)) {
$command->index = $prefix.$command->index;
}
}
}
}