collation required not optional when creating db

This commit is contained in:
Crivion
2025-10-18 16:53:45 +03:00
parent a22aac2656
commit f22a8d7eec
2 changed files with 20 additions and 10 deletions

View File

@@ -91,7 +91,7 @@ class MysqlController extends Controller
'db_user' => ['required', 'string'],
'db_pass' => ['required', 'string'],
'charset' => ['required', 'string'],
'collation' => ['nullable', 'string'],
'collation' => ['required', 'string'],
]);
$user = $request->user();
@@ -112,11 +112,7 @@ class MysqlController extends Controller
}
// Create database with charset and collation
$sql = "CREATE DATABASE `$name` CHARACTER SET $charset";
if ($collation) {
$sql .= " COLLATE $collation";
}
DB::statement($sql);
DB::statement("CREATE DATABASE `$name` CHARACTER SET $charset COLLATE $collation");
// Create user (if not exists) and grant all privileges on the new DB
DB::statement("CREATE USER IF NOT EXISTS `$dbUser`@'localhost' IDENTIFIED BY '$dbPass'");