Merge pull request #1239 from cnurse/dev

Implement Database Migrations and add Multi-Database Support
This commit is contained in:
Shaun Walker
2021-04-19 21:11:11 -04:00
committed by GitHub
108 changed files with 4006 additions and 453 deletions

View File

@ -1,3 +1,5 @@
@using Oqtane.Interfaces
@using System.Reflection
@namespace Oqtane.UI
@inject NavigationManager NavigationManager
@inject IInstallationService InstallationService
@ -5,6 +7,7 @@
@inject IUserService UserService
@inject IJSRuntime JSRuntime
@inject IStringLocalizer<Installer> Localizer
@inject IEnumerable<IOqtaneDatabase> Databases
<div class="container">
<div class="row">
@ -25,54 +28,59 @@
</td>
<td>
<select class="custom-select" @bind="@_databaseType">
<option value="LocalDB">@Localizer["Local Database"]</option>
<option value="SQLServer">@Localizer["SQL Server"]</option>
@{
foreach (var database in Databases)
{
<option value="@database.Name">@Localizer[@database.FriendlyName]</option>
}
}
</select>
</td>
</tr>
<tr>
<td>
<label class="control-label" style="font-weight: bold">@Localizer["Server:"] </label>
</td>
<td>
<input type="text" class="form-control" @bind="@_serverName" />
</td>
</tr>
<tr>
<td>
<label class="control-label" style="font-weight: bold">@Localizer["Database:"] </label>
</td>
<td>
<input type="text" class="form-control" @bind="@_databaseName" />
</td>
</tr>
<tr>
<td>
<label class="control-label" style="font-weight: bold">@Localizer["Integrated Security:"] </label>
</td>
<td>
<select class="custom-select" @onchange="SetIntegratedSecurity">
<option value="true" selected>@Localizer["True"]</option>
<option value="false">@Localizer["False"]</option>
</select>
</td>
</tr>
<tr style="@_integratedSecurityDisplay">
<td>
<label class="control-label" style="font-weight: bold">@Localizer["Username:"] </label>
</td>
<td>
<input type="text" class="form-control" @bind="@_username" />
</td>
</tr>
<tr style="@_integratedSecurityDisplay">
<td>
<label class="control-label" style="font-weight: bold">@Localizer["Password:"] </label>
</td>
<td>
<input type="password" class="form-control" @bind="@_password" />
</td>
</tr>
@{
_selectedDatabase = Databases.Single(d => d.Name == _databaseType);
foreach (var field in _selectedDatabase.ConnectionStringFields)
{
if (field.Name != "IntegratedSecurity")
{
var isVisible = "";
var fieldType = (field.Name == "Pwd") ? "password" : "text";
if ((field.Name == "Uid" || field.Name == "Pwd") && _selectedDatabase.Name != "MySQL" )
{
var intSecurityField = _selectedDatabase.ConnectionStringFields.Single(f => f.Name == "IntegratedSecurity");
if (intSecurityField != null)
{
isVisible = (Convert.ToBoolean(intSecurityField.Value)) ? "display: none;" : "";
}
}
field.Value = field.Value.Replace("{{Date}}", DateTime.UtcNow.ToString("yyyyMMddHHmm"));
<tr style="@isVisible">
<td>
<label class="control-label" style="font-weight: bold">@Localizer[$"{field.FriendlyName}:"]</label>
</td>
<td>
<input type="@fieldType" class="form-control" @bind="@field.Value" />
</td>
</tr>
}
else
{
<tr>
<td>
<label class="control-label" style="font-weight: bold">@Localizer[$"{field.FriendlyName}:"]</label>
</td>
<td>
<select class="custom-select" @bind="@field.Value">
<option value="true" selected>@Localizer["True"]</option>
<option value="false">@Localizer["False"]</option>
</select>
</td>
</tr>
}
}
}
</tbody>
</table>
</div>
@ -127,17 +135,13 @@
</div>
@code {
private IOqtaneDatabase _selectedDatabase;
private string _databaseType = "LocalDB";
private string _serverName = "(LocalDb)\\MSSQLLocalDB";
private string _databaseName = "Oqtane-" + DateTime.UtcNow.ToString("yyyyMMddHHmm");
private string _username = string.Empty;
private string _password = string.Empty;
private string _hostUsername = UserNames.Host;
private string _hostPassword = string.Empty;
private string _confirmPassword = string.Empty;
private string _hostEmail = string.Empty;
private string _message = string.Empty;
private string _integratedSecurityDisplay = "display: none;";
private string _loadingDisplay = "display: none;";
protected override async Task OnAfterRenderAsync(bool firstRender)
@ -149,43 +153,21 @@
}
}
private void SetIntegratedSecurity(ChangeEventArgs e)
{
_integratedSecurityDisplay = Convert.ToBoolean((string)e.Value)
? "display: none;"
: string.Empty;
}
private async Task Install()
{
if (_serverName != "" && _databaseName != "" && _hostUsername != "" && _hostPassword.Length >= 6 && _hostPassword == _confirmPassword && _hostEmail != "")
var connectionString = _selectedDatabase.BuildConnectionString();
if (connectionString != "" && _hostUsername != "" && _hostPassword.Length >= 6 && _hostPassword == _confirmPassword && _hostEmail != "")
{
_loadingDisplay = "";
StateHasChanged();
var connectionstring = "";
if (_databaseType == "LocalDB")
{
connectionstring = "Data Source=" + _serverName + ";AttachDbFilename=|DataDirectory|\\" + _databaseName + ".mdf;Initial Catalog=" + _databaseName + ";Integrated Security=SSPI;";
}
else
{
connectionstring = "Data Source=" + _serverName + ";Initial Catalog=" + _databaseName + ";";
if (_integratedSecurityDisplay == "display: none;")
{
connectionstring += "Integrated Security=SSPI;";
}
else
{
connectionstring += "User ID=" + _username + ";Password=" + _password;
}
}
Uri uri = new Uri(NavigationManager.Uri);
var config = new InstallConfig
{
ConnectionString = connectionstring,
DatabaseType = _databaseType,
ConnectionString = connectionString,
Aliases = uri.Authority,
HostEmail = _hostEmail,
HostPassword = _hostPassword,