|
@@ -28,11 +28,11 @@ class ProjectServer extends BaseService |
|
@@ -28,11 +28,11 @@ class ProjectServer extends BaseService |
|
28
|
if (empty($project))
|
28
|
if (empty($project))
|
|
29
|
return false;
|
29
|
return false;
|
|
30
|
// 设置 database.connections.custom_mysql 配置
|
30
|
// 设置 database.connections.custom_mysql 配置
|
|
31
|
- config(['database.connections.custom_mysql.host' => $project->mysqlConfig()->host]);
|
|
|
|
32
|
- config(['database.connections.custom_mysql.port' => $project->mysqlConfig()->port]);
|
31
|
+ config(['database.connections.custom_mysql.host' => $project->mysqlConfig->host]);
|
|
|
|
32
|
+ config(['database.connections.custom_mysql.port' => $project->mysqlConfig->port]);
|
|
33
|
config(['database.connections.custom_mysql.database' => $project->databaseName()]);
|
33
|
config(['database.connections.custom_mysql.database' => $project->databaseName()]);
|
|
34
|
- config(['database.connections.custom_mysql.username' => $project->mysqlConfig()->user]);
|
|
|
|
35
|
- config(['database.connections.custom_mysql.password' => $project->mysqlConfig()->password]);
|
34
|
+ config(['database.connections.custom_mysql.username' => $project->mysqlConfig->user]);
|
|
|
|
35
|
+ config(['database.connections.custom_mysql.password' => $project->mysqlConfig->password]);
|
|
36
|
// 设置 redis 配置
|
36
|
// 设置 redis 配置
|
|
37
|
return $project;
|
37
|
return $project;
|
|
38
|
}
|
38
|
}
|
|
@@ -40,40 +40,39 @@ class ProjectServer extends BaseService |
|
@@ -40,40 +40,39 @@ class ProjectServer extends BaseService |
|
40
|
|
40
|
|
|
41
|
/**
|
41
|
/**
|
|
42
|
* 创建数据库
|
42
|
* 创建数据库
|
|
43
|
- * @param $project_id
|
43
|
+ * @param $project
|
|
|
|
44
|
+ * @return bool
|
|
44
|
* @author zbj
|
45
|
* @author zbj
|
|
45
|
* @date 2023/4/23
|
46
|
* @date 2023/4/23
|
|
46
|
*/
|
47
|
*/
|
|
47
|
- public static function createDatabase($project_id){
|
|
|
|
48
|
- $project = self::useProject($project_id);
|
|
|
|
49
|
- DB::connection('custom_mysql')->statement("CREATE DATABASE IF NOT EXISTS {$project->databaseName()}");
|
48
|
+ public static function createDatabase($project)
|
|
|
|
49
|
+ {
|
|
|
|
50
|
+ $conn = new \mysqli($project->mysqlConfig->host, $project->mysqlConfig->user, $project->mysqlConfig->password);
|
|
|
|
51
|
+ $conn->query("CREATE DATABASE IF NOT EXISTS {$project->databaseName()}");
|
|
|
|
52
|
+ return true;
|
|
50
|
}
|
53
|
}
|
|
51
|
|
54
|
|
|
52
|
|
55
|
|
|
53
|
/**
|
56
|
/**
|
|
54
|
- * @param $project_id
|
57
|
+ * @param $project
|
|
55
|
* @return bool
|
58
|
* @return bool
|
|
56
|
- * @throws \Doctrine\DBAL\Exception
|
|
|
|
57
|
* @author zbj
|
59
|
* @author zbj
|
|
58
|
* @date 2023/4/23
|
60
|
* @date 2023/4/23
|
|
59
|
*/
|
61
|
*/
|
|
60
|
- public static function initTable($project_id){
|
|
|
|
61
|
- $project = self::useProject($project_id);
|
62
|
+ public static function initTable($project)
|
|
|
|
63
|
+ {
|
|
62
|
$database_name = DB::connection('custom_tmp_mysql')->getDatabaseName();
|
64
|
$database_name = DB::connection('custom_tmp_mysql')->getDatabaseName();
|
|
63
|
|
65
|
|
|
64
|
$table = Schema::connection('custom_tmp_mysql')->getAllTables();
|
66
|
$table = Schema::connection('custom_tmp_mysql')->getAllTables();
|
|
65
|
$table = array_column($table, 'Tables_in_' . $database_name);
|
67
|
$table = array_column($table, 'Tables_in_' . $database_name);
|
|
66
|
foreach ($table as $v) {
|
68
|
foreach ($table as $v) {
|
|
67
|
$has_table = Schema::connection('custom_mysql')->hasTable($v);
|
69
|
$has_table = Schema::connection('custom_mysql')->hasTable($v);
|
|
68
|
- if ($has_table)
|
70
|
+ if ($has_table) {
|
|
69
|
continue;
|
71
|
continue;
|
|
|
|
72
|
+ }
|
|
70
|
|
73
|
|
|
71
|
- $connection = DB::connection('custom_tmp_mysql');
|
|
|
|
72
|
- $sql = $connection->getDoctrineSchemaManager()
|
|
|
|
73
|
- ->getDatabasePlatform()
|
|
|
|
74
|
- ->getCreateTableSQL($connection->getDoctrineSchemaManager()->listTableDetails($v));
|
|
|
|
75
|
-
|
|
|
|
76
|
- DB::connection('custom_mysql')->select($sql[0]);
|
74
|
+ $sql = DB::connection('custom_tmp_mysql')->select("SHOW CREATE TABLE {$v}");
|
|
|
|
75
|
+ DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']);
|
|
77
|
}
|
76
|
}
|
|
78
|
return true;
|
77
|
return true;
|
|
79
|
}
|
78
|
}
|