mirror of
https://github.com/flarum/core.git
synced 2025-08-06 08:27:42 +02:00
Fix index names in migrations
This can be reverted when we upgrade to Laravel 5.7.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Flarum\Database\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Schema\Builder;
|
||||
|
||||
@@ -23,14 +24,18 @@ return [
|
||||
})
|
||||
->delete();
|
||||
|
||||
$schema->table('access_tokens', function (Blueprint $table) {
|
||||
$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) {
|
||||
$schema->table('access_tokens', function (Blueprint $table) use ($schema) {
|
||||
$table->dropForeign(['user_id']);
|
||||
|
||||
Migration::fixIndexNames($schema, $table);
|
||||
});
|
||||
}
|
||||
];
|
||||
|
@@ -9,18 +9,21 @@
|
||||
* 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) {
|
||||
$schema->table('api_keys', function (Blueprint $table) use ($schema) {
|
||||
$table->dropPrimary(['id']);
|
||||
$table->renameColumn('id', 'key');
|
||||
$table->unique('key');
|
||||
|
||||
Migration::fixIndexNames($schema, $table);
|
||||
});
|
||||
|
||||
$schema->table('api_keys', function (Blueprint $table) {
|
||||
$schema->table('api_keys', function (Blueprint $table) use ($schema) {
|
||||
$table->increments('id');
|
||||
$table->string('allowed_ips')->nullable();
|
||||
$table->string('scopes')->nullable();
|
||||
@@ -29,19 +32,25 @@ 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) {
|
||||
$schema->table('api_keys', function (Blueprint $table) use ($schema) {
|
||||
$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) {
|
||||
$schema->table('api_keys', function (Blueprint $table) use ($schema) {
|
||||
$table->dropUnique(['key']);
|
||||
$table->renameColumn('key', 'id');
|
||||
$table->primary('id');
|
||||
|
||||
Migration::fixIndexNames($schema, $table);
|
||||
});
|
||||
}
|
||||
];
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* 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;
|
||||
@@ -33,21 +34,25 @@ return [
|
||||
'last_post_id' => $selectId('posts', 'last_post_id'),
|
||||
]);
|
||||
|
||||
$schema->table('discussions', function (Blueprint $table) {
|
||||
$schema->table('discussions', function (Blueprint $table) use ($schema) {
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('set null');
|
||||
$table->foreign('last_posted_user_id')->references('id')->on('users')->onDelete('set null');
|
||||
$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);
|
||||
});
|
||||
},
|
||||
|
||||
'down' => function (Builder $schema) {
|
||||
$schema->table('discussions', function (Blueprint $table) {
|
||||
$schema->table('discussions', function (Blueprint $table) use ($schema) {
|
||||
$table->dropForeign([
|
||||
'user_id', 'last_posted_user_id', 'hidden_user_id',
|
||||
'first_post_id', 'last_post_id'
|
||||
]);
|
||||
|
||||
Migration::fixIndexNames($schema, $table);
|
||||
});
|
||||
}
|
||||
];
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Flarum\Database\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Schema\Builder;
|
||||
|
||||
@@ -26,15 +27,19 @@ return [
|
||||
})
|
||||
->delete();
|
||||
|
||||
$schema->table('discussion_user', function (Blueprint $table) {
|
||||
$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);
|
||||
});
|
||||
},
|
||||
|
||||
'down' => function (Builder $schema) {
|
||||
$schema->table('discussion_user', function (Blueprint $table) {
|
||||
$schema->table('discussion_user', function (Blueprint $table) use ($schema) {
|
||||
$table->dropForeign(['user_id', 'discussion_id']);
|
||||
|
||||
Migration::fixIndexNames($schema, $table);
|
||||
});
|
||||
}
|
||||
];
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Flarum\Database\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Schema\Builder;
|
||||
|
||||
@@ -23,14 +24,18 @@ return [
|
||||
})
|
||||
->delete();
|
||||
|
||||
$schema->table('email_tokens', function (Blueprint $table) {
|
||||
$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) {
|
||||
$schema->table('email_tokens', function (Blueprint $table) use ($schema) {
|
||||
$table->dropForeign(['user_id']);
|
||||
|
||||
Migration::fixIndexNames($schema, $table);
|
||||
});
|
||||
}
|
||||
];
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Flarum\Database\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Schema\Builder;
|
||||
|
||||
@@ -23,14 +24,18 @@ return [
|
||||
})
|
||||
->delete();
|
||||
|
||||
$schema->table('group_permission', function (Blueprint $table) {
|
||||
$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) {
|
||||
$schema->table('group_permission', function (Blueprint $table) use ($schema) {
|
||||
$table->dropForeign(['group_id']);
|
||||
|
||||
Migration::fixIndexNames($schema, $table);
|
||||
});
|
||||
}
|
||||
];
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Flarum\Database\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Schema\Builder;
|
||||
|
||||
@@ -26,15 +27,19 @@ return [
|
||||
})
|
||||
->delete();
|
||||
|
||||
$schema->table('group_user', function (Blueprint $table) {
|
||||
$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);
|
||||
});
|
||||
},
|
||||
|
||||
'down' => function (Builder $schema) {
|
||||
$schema->table('group_user', function (Blueprint $table) {
|
||||
$schema->table('group_user', function (Blueprint $table) use ($schema) {
|
||||
$table->dropForeign(['user_id', 'group_id']);
|
||||
|
||||
Migration::fixIndexNames($schema, $table);
|
||||
});
|
||||
}
|
||||
];
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Flarum\Database\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Schema\Builder;
|
||||
|
||||
@@ -30,15 +31,19 @@ return [
|
||||
})
|
||||
->update(['from_user_id' => null]);
|
||||
|
||||
$schema->table('notifications', function (Blueprint $table) {
|
||||
$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);
|
||||
});
|
||||
},
|
||||
|
||||
'down' => function (Builder $schema) {
|
||||
$schema->table('notifications', function (Blueprint $table) {
|
||||
$schema->table('notifications', function (Blueprint $table) use ($schema) {
|
||||
$table->dropForeign(['user_id', 'from_user_id']);
|
||||
|
||||
Migration::fixIndexNames($schema, $table);
|
||||
});
|
||||
}
|
||||
];
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Flarum\Database\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Schema\Builder;
|
||||
|
||||
@@ -23,14 +24,18 @@ return [
|
||||
})
|
||||
->delete();
|
||||
|
||||
$schema->table('password_tokens', function (Blueprint $table) {
|
||||
$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) {
|
||||
$schema->table('password_tokens', function (Blueprint $table) use ($schema) {
|
||||
$table->dropForeign(['user_id']);
|
||||
|
||||
Migration::fixIndexNames($schema, $table);
|
||||
});
|
||||
}
|
||||
];
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* 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;
|
||||
@@ -31,19 +32,23 @@ return [
|
||||
'hidden_user_id' => $selectId('users', 'hidden_user_id'),
|
||||
]);
|
||||
|
||||
$schema->table('posts', function (Blueprint $table) {
|
||||
$schema->table('posts', function (Blueprint $table) use ($schema) {
|
||||
$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);
|
||||
});
|
||||
},
|
||||
|
||||
'down' => function (Builder $schema) {
|
||||
$schema->table('posts', function (Blueprint $table) {
|
||||
$schema->table('posts', function (Blueprint $table) use ($schema) {
|
||||
$table->dropForeign([
|
||||
'user_id', 'discussion_id',
|
||||
'edited_user_id', 'hidden_user_id'
|
||||
]);
|
||||
|
||||
Migration::fixIndexNames($schema, $table);
|
||||
});
|
||||
}
|
||||
];
|
||||
|
@@ -9,25 +9,30 @@
|
||||
* 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('users', function (Blueprint $table) {
|
||||
$schema->table('users', function (Blueprint $table) use ($schema) {
|
||||
$table->index('joined_at');
|
||||
$table->index('last_seen_at');
|
||||
$table->index('discussion_count');
|
||||
$table->index('comment_count');
|
||||
|
||||
Migration::fixIndexNames($schema, $table);
|
||||
});
|
||||
},
|
||||
|
||||
'down' => function (Builder $schema) {
|
||||
$schema->table('users', function (Blueprint $table) {
|
||||
$schema->table('users', function (Blueprint $table) use ($schema) {
|
||||
$table->dropIndex(['joined_at']);
|
||||
$table->dropIndex(['last_seen_at']);
|
||||
$table->dropIndex(['discussion_count']);
|
||||
$table->dropIndex(['comment_count']);
|
||||
|
||||
Migration::fixIndexNames($schema, $table);
|
||||
});
|
||||
}
|
||||
];
|
||||
|
@@ -9,12 +9,13 @@
|
||||
* 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('discussions', function (Blueprint $table) {
|
||||
$schema->table('discussions', function (Blueprint $table) use ($schema) {
|
||||
$table->index('last_posted_at');
|
||||
$table->index('last_posted_user_id');
|
||||
$table->index('created_at');
|
||||
@@ -22,11 +23,13 @@ return [
|
||||
$table->index('comment_count');
|
||||
$table->index('participant_count');
|
||||
$table->index('hidden_at');
|
||||
|
||||
Migration::fixIndexNames($schema, $table);
|
||||
});
|
||||
},
|
||||
|
||||
'down' => function (Builder $schema) {
|
||||
$schema->table('discussions', function (Blueprint $table) {
|
||||
$schema->table('discussions', function (Blueprint $table) use ($schema) {
|
||||
$table->dropIndex(['last_posted_at']);
|
||||
$table->dropIndex(['last_posted_user_id']);
|
||||
$table->dropIndex(['created_at']);
|
||||
@@ -34,6 +37,8 @@ return [
|
||||
$table->dropIndex(['comment_count']);
|
||||
$table->dropIndex(['participant_count']);
|
||||
$table->dropIndex(['hidden_at']);
|
||||
|
||||
Migration::fixIndexNames($schema, $table);
|
||||
});
|
||||
}
|
||||
];
|
||||
|
@@ -9,19 +9,24 @@
|
||||
* 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('notifications', function (Blueprint $table) {
|
||||
$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) {
|
||||
$schema->table('notifications', function (Blueprint $table) use ($schema) {
|
||||
$table->dropIndex(['user_id']);
|
||||
|
||||
Migration::fixIndexNames($schema, $table);
|
||||
});
|
||||
}
|
||||
];
|
||||
|
@@ -9,23 +9,28 @@
|
||||
* 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('posts', function (Blueprint $table) {
|
||||
$schema->table('posts', function (Blueprint $table) use ($schema) {
|
||||
$table->index(['discussion_id', 'number']);
|
||||
$table->index(['discussion_id', 'created_at']);
|
||||
$table->index(['user_id', 'created_at']);
|
||||
|
||||
Migration::fixIndexNames($schema, $table);
|
||||
});
|
||||
},
|
||||
|
||||
'down' => function (Builder $schema) {
|
||||
$schema->table('posts', function (Blueprint $table) {
|
||||
$schema->table('posts', function (Blueprint $table) use ($schema) {
|
||||
$table->dropIndex(['discussion_id', 'number']);
|
||||
$table->dropIndex(['discussion_id', 'created_at']);
|
||||
$table->dropIndex(['user_id', 'created_at']);
|
||||
|
||||
Migration::fixIndexNames($schema, $table);
|
||||
});
|
||||
}
|
||||
];
|
||||
|
Reference in New Issue
Block a user