diff --git a/BootstrapAdmin.sln b/BootstrapAdmin.sln index 00c43c05..b57df96b 100644 --- a/BootstrapAdmin.sln +++ b/BootstrapAdmin.sln @@ -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 diff --git a/db/MySQL/install.ps1 b/db/MySQL/install.ps1 new file mode 100644 index 00000000..82f44f6f --- /dev/null +++ b/db/MySQL/install.ps1 @@ -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 diff --git a/src/admin/Bootstrap.DataAccess/AutoDB.cs b/src/admin/Bootstrap.DataAccess/AutoDB.cs index 11f8df86..184de566 100644 --- a/src/admin/Bootstrap.DataAccess/AutoDB.cs +++ b/src/admin/Bootstrap.DataAccess/AutoDB.cs @@ -29,13 +29,13 @@ namespace Bootstrap.DataAccess case "SqlServerDatabaseProvider": using (var newDB = ModifyConnectionString(db)) { - if (newDB.ExecuteScalar("select COUNT(*) from sys.databases where name = N'BootstrapAdmin'") == 0) GenerateSqlServer(); + if (newDB.ExecuteScalar("select COUNT(*) from sys.databases where name = N'BootstrapAdmin'") == 0) GenerateDB(); } break; case "MySqlDatabaseProvider": case "MariaDbDatabaseProvider": // UNDONE: 本地没有环境此处代码未测试 - if (db.ExecuteScalar("select count(*) from information_schema.tables where table_name ='Users' and Table_Schema = 'BootstrapAdmin'") == 0) GenerateMySql(); + if (db.ExecuteScalar("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: 没有环境暂时未写代码 - } } }