feat(#I12XMD): MySQL 自动建库

#Issue
close https://gitee.com/LongbowEnterprise/dashboard/issues?id=I12XMD
This commit is contained in:
Argo Window10 2019-11-16 14:00:56 +08:00
parent 2742b459e9
commit 412989012b
3 changed files with 13 additions and 8 deletions

View File

@ -43,6 +43,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MySQL", "MySQL", "{084E2E94-6B7D-4D3E-9BF1-6972427FBF80}"
ProjectSection(SolutionItems) = preProject
db\MySQL\initData.sql = db\MySQL\initData.sql
db\MySQL\install.ps1 = db\MySQL\install.ps1
db\MySQL\install.sh = db\MySQL\install.sh
db\MySQL\install.sql = db\MySQL\install.sql
db\MySQL\my.ini = db\MySQL\my.ini

9
db/MySQL/install.ps1 Normal file
View File

@ -0,0 +1,9 @@
# init mysql database
$startPath = $args[0]
if ($startPath -eq $null) {
$startPath = "Z:\src\Longbow\BootstrapAdmin\db\SqlServer"
}
mysql -e "drop database if exists BootstrapAdmin; create database BootstrapAdmin;" -uroot
mysql -hlocalhost -uroot -DBootstrapAdmin < $startPath\install.sql
mysql -hlocalhost -uroot -DBootstrapAdmin < $startPath\initData.sql

View File

@ -29,13 +29,13 @@ namespace Bootstrap.DataAccess
case "SqlServerDatabaseProvider":
using (var newDB = ModifyConnectionString(db))
{
if (newDB.ExecuteScalar<int?>("select COUNT(*) from sys.databases where name = N'BootstrapAdmin'") == 0) GenerateSqlServer();
if (newDB.ExecuteScalar<int?>("select COUNT(*) from sys.databases where name = N'BootstrapAdmin'") == 0) GenerateDB();
}
break;
case "MySqlDatabaseProvider":
case "MariaDbDatabaseProvider":
// UNDONE: 本地没有环境此处代码未测试
if (db.ExecuteScalar<int>("select count(*) from information_schema.tables where table_name ='Users' and Table_Schema = 'BootstrapAdmin'") == 0) GenerateMySql();
if (db.ExecuteScalar<int>("select count(*) from information_schema.tables where table_name ='Users' and Table_Schema = 'BootstrapAdmin'") == 0) GenerateDB();
break;
}
}
@ -72,7 +72,7 @@ namespace Bootstrap.DataAccess
}
}
private void GenerateSqlServer()
private void GenerateDB()
{
// 检查 install.ps1 脚本
var file = Path.Combine(_folder, $"install.ps1");
@ -83,10 +83,5 @@ namespace Bootstrap.DataAccess
p.WaitForExit();
}
}
private void GenerateMySql()
{
// UNDONE: 没有环境暂时未写代码
}
}
}