Database Manager

done:
+ master.sql as resource
+ implemented incremental database changes also for Master
+ dbUp sql script variables implemented
+ improved database handling and creation code
+ simpified database creation
+ almost all Database and Tenant creation moved to DatabaseManager.cs (rest code marked with TODO)
+ Unattended install of master can be performed by settings in appsettings.json
+ Improved IsInstalled checking
+ Removed DBSchema field from Tenant
+ Default database and site creation moved to Program.Main
This commit is contained in:
Pavel Vesely
2020-03-25 15:30:16 +01:00
parent 744782df7a
commit 940cdcb349
26 changed files with 726 additions and 525 deletions

View File

@ -164,7 +164,7 @@ else
_tenantid = (string)e.Value;
if (_tenantid != "-1")
{
Tenant tenant = _tenants.Where(item => item.TenantId == int.Parse(_tenantid)).FirstOrDefault();
Tenant tenant = _tenants.FirstOrDefault(item => item.TenantId == int.Parse(_tenantid));
if (tenant != null)
{
_isinitialized = tenant.IsInitialized;
@ -273,8 +273,11 @@ else
if (user != null)
{
Tenant tenant = _tenants.FirstOrDefault(item => item.TenantId == int.Parse(_tenantid));
tenant.IsInitialized = true;
await TenantService.UpdateTenantAsync(tenant);
if (tenant != null)
{
tenant.IsInitialized = true;
await TenantService.UpdateTenantAsync(tenant);
}
}
}
await Log(aliases[0], LogLevel.Information, "", null, "Site Created {Site}", site);

View File

@ -67,14 +67,6 @@
<input type="password" class="form-control" @bind="@password" />
</td>
</tr>
<tr>
<td>
<label class="control-label">Schema: </label>
</td>
<td>
<input class="form-control" @bind="@schema" />
</td>
</tr>
</table>
<button type="button" class="btn btn-success" @onclick="SaveTenant">Save</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
@ -88,7 +80,6 @@
string database = "Oqtane-" + DateTime.UtcNow.ToString("yyyyMMddHHmm");
string username = "";
string password = "";
string schema = "";
string integratedsecurity = "display: none;";
private void SetIntegratedSecurity(ChangeEventArgs e)
@ -109,32 +100,41 @@
{
ShowProgressIndicator();
string connectionstring = "";
string connectionString = "";
if (type == "LocalDB")
{
connectionstring = "Data Source=" + server + ";AttachDbFilename=|DataDirectory|\\" + database + ".mdf;Initial Catalog=" + database + ";Integrated Security=SSPI;";
connectionString = "Data Source=" + server + ";AttachDbFilename=|DataDirectory|\\" + database + ".mdf;Initial Catalog=" + database + ";Integrated Security=SSPI;";
}
else
{
connectionstring = "Data Source=" + server + ";Initial Catalog=" + database + ";";
connectionString = "Data Source=" + server + ";Initial Catalog=" + database + ";";
if (integratedsecurity == "display: none;")
{
connectionstring += "Integrated Security=SSPI;";
connectionString += "Integrated Security=SSPI;";
}
else
{
connectionstring += "User ID=" + username + ";Password=" + password;
connectionString += "User ID=" + username + ";Password=" + password;
}
}
Installation installation = await InstallationService.Install(connectionstring);
var config = new InstallConfig
{
IsMaster = false,
ConnectionString = connectionString,
};
Installation installation = await InstallationService.Install(config);
if (installation.Success)
{
Tenant tenant = new Tenant();
tenant.Name = name;
tenant.DBConnectionString = connectionstring;
tenant.DBSchema = schema;
tenant.IsInitialized = false;
//TODO : Move to Database Manager
Tenant tenant = new Tenant
{
Name = name,
DBConnectionString = connectionString,
IsInitialized = false
};
await TenantService.AddTenantAsync(tenant);
await logger.LogInformation("Tenant Created {Tenant}", tenant);

View File

@ -20,14 +20,7 @@
<input class="form-control" @bind="@connectionstring" />
</td>
</tr>
<tr>
<td>
<label class="control-label">Schema: </label>
</td>
<td>
<input class="form-control" @bind="@schema" />
</td>
</tr>
</table>
<button type="button" class="btn btn-success" @onclick="SaveTenant">Save</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
@ -38,7 +31,6 @@
int tenantid;
string name = "";
string connectionstring = "";
string schema = "";
protected override async Task OnInitializedAsync()
{
@ -50,7 +42,6 @@
{
name = tenant.Name;
connectionstring = tenant.DBConnectionString;
schema = tenant.DBSchema;
}
}
catch (Exception ex)
@ -70,7 +61,6 @@
{
tenant.Name = name;
tenant.DBConnectionString = connectionstring;
tenant.DBSchema = schema;
await TenantService.UpdateTenantAsync(tenant);
await logger.LogInformation("Tenant Saved {TenantId}", tenantid);

View File

@ -19,24 +19,21 @@ namespace Oqtane.Services
_navigationManager = navigationManager;
}
private string Apiurl
{
get { return CreateApiUrl(_siteState.Alias, _navigationManager.Uri, "Installation"); }
}
private string ApiUrl => CreateApiUrl(_siteState.Alias, _navigationManager.Uri, "Installation");
public async Task<Installation> IsInstalled()
{
return await _http.GetJsonAsync<Installation>(Apiurl + "/installed");
return await _http.GetJsonAsync<Installation>(ApiUrl + "/installed");
}
public async Task<Installation> Install(string connectionstring)
public async Task<Installation> Install(InstallConfig config)
{
return await _http.PostJsonAsync<Installation>(Apiurl, connectionstring);
return await _http.PostJsonAsync<Installation>(ApiUrl, config);
}
public async Task<Installation> Upgrade()
{
return await _http.GetJsonAsync<Installation>(Apiurl + "/upgrade");
return await _http.GetJsonAsync<Installation>(ApiUrl + "/upgrade");
}
}
}

View File

@ -1,12 +1,13 @@
using Oqtane.Models;
using System.Threading.Tasks;
using Oqtane.Shared;
namespace Oqtane.Services
{
public interface IInstallationService
{
Task<Installation> IsInstalled();
Task<Installation> Install(string connectionstring);
Task<Installation> Install(InstallConfig config);
Task<Installation> Upgrade();
}
}

View File

@ -7,117 +7,117 @@
<div class="container">
<div class="row">
<div class="mx-auto text-center">
<img src="oqtane.png" />
<img src="oqtane.png"/>
</div>
</div>
<hr class="app-rule" />
<hr class="app-rule"/>
<div class="row justify-content-center">
<div class="col text-center">
<h2>Database Configuration</h2><br />
<h2>Database Configuration</h2><br/>
<table class="form-group" cellpadding="4" cellspacing="4" style="margin: auto;">
<tbody>
<tr>
<td>
<label class="control-label" style="font-weight: bold">Database Type: </label>
</td>
<td>
<select class="custom-select" @bind="@_databaseType">
<option value="LocalDB">Local Database</option>
<option value="SQLServer">SQL Server</option>
</select>
</td>
</tr>
<tr>
<td>
<label class="control-label" style="font-weight: bold">Server: </label>
</td>
<td>
<input type="text" class="form-control" @bind="@_serverName" />
</td>
</tr>
<tr>
<td>
<label class="control-label" style="font-weight: bold">Database: </label>
</td>
<td>
<input type="text" class="form-control" @bind="@_databaseName" />
</td>
</tr>
<tr>
<td>
<label class="control-label" style="font-weight: bold">Integrated Security: </label>
</td>
<td>
<select class="custom-select" @onchange="SetIntegratedSecurity">
<option value="true" selected>True</option>
<option value="false">False</option>
</select>
</td>
</tr>
<tr style="@_integratedSecurityDisplay">
<td>
<label class="control-label" style="font-weight: bold">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">Password: </label>
</td>
<td>
<input type="password" class="form-control" @bind="@_password" />
</td>
</tr>
<tr>
<td>
<label class="control-label" style="font-weight: bold">Database Type: </label>
</td>
<td>
<select class="custom-select" @bind="@_databaseType">
<option value="LocalDB">Local Database</option>
<option value="SQLServer">SQL Server</option>
</select>
</td>
</tr>
<tr>
<td>
<label class="control-label" style="font-weight: bold">Server: </label>
</td>
<td>
<input type="text" class="form-control" @bind="@_serverName"/>
</td>
</tr>
<tr>
<td>
<label class="control-label" style="font-weight: bold">Database: </label>
</td>
<td>
<input type="text" class="form-control" @bind="@_databaseName"/>
</td>
</tr>
<tr>
<td>
<label class="control-label" style="font-weight: bold">Integrated Security: </label>
</td>
<td>
<select class="custom-select" @onchange="SetIntegratedSecurity">
<option value="true" selected>True</option>
<option value="false">False</option>
</select>
</td>
</tr>
<tr style="@_integratedSecurityDisplay">
<td>
<label class="control-label" style="font-weight: bold">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">Password: </label>
</td>
<td>
<input type="password" class="form-control" @bind="@_password"/>
</td>
</tr>
</tbody>
</table>
</div>
<div class="col text-center">
<h2>Application Administrator</h2><br />
<h2>Application Administrator</h2><br/>
<table class="form-group" cellpadding="4" cellspacing="4" style="margin: auto;">
<tbody>
<tr>
<td>
<label class="control-label" style="font-weight: bold">Username: </label>
</td>
<td>
<input type="text" class="form-control" @bind="@_hostUsername" readonly />
</td>
</tr>
<tr>
<td>
<label class="control-label" style="font-weight: bold">Password: </label>
</td>
<td>
<input type="password" class="form-control" @bind="@_hostPassword" />
</td>
</tr>
<tr>
<td>
<label class="control-label" style="font-weight: bold">Confirm: </label>
</td>
<td>
<input type="password" class="form-control" @bind="@_confirmPassword" />
</td>
</tr>
<tr>
<td>
<label class="control-label" style="font-weight: bold">Email: </label>
</td>
<td>
<input type="text" class="form-control" @bind="@_hostEmail" />
</td>
</tr>
<tr>
<td>
<label class="control-label" style="font-weight: bold">Username: </label>
</td>
<td>
<input type="text" class="form-control" @bind="@_hostUsername" readonly/>
</td>
</tr>
<tr>
<td>
<label class="control-label" style="font-weight: bold">Password: </label>
</td>
<td>
<input type="password" class="form-control" @bind="@_hostPassword"/>
</td>
</tr>
<tr>
<td>
<label class="control-label" style="font-weight: bold">Confirm: </label>
</td>
<td>
<input type="password" class="form-control" @bind="@_confirmPassword"/>
</td>
</tr>
<tr>
<td>
<label class="control-label" style="font-weight: bold">Email: </label>
</td>
<td>
<input type="text" class="form-control" @bind="@_hostEmail"/>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<hr class="app-rule" />
<hr class="app-rule"/>
<div class="row">
<div class="mx-auto text-center">
<button type="button" class="btn btn-success" @onclick="Install">Install Now</button><br /><br />
@((MarkupString)_message)
<button type="button" class="btn btn-success" @onclick="Install">Install Now</button><br/><br/>
@((MarkupString) _message)
</div>
<div class="app-progress-indicator" style="@_loadingDisplay"></div>
</div>
@ -140,7 +140,7 @@
private void SetIntegratedSecurity(ChangeEventArgs e)
{
if (Convert.ToBoolean((string)e.Value))
if (Convert.ToBoolean((string) e.Value))
{
_integratedSecurityDisplay = "display: none;";
}
@ -172,10 +172,20 @@
else
{
connectionstring += "User ID=" + _username + ";Password=" + _password;
}
}
Installation installation = await InstallationService.Install(connectionstring);
var config = new InstallConfig
{
ConnectionString = connectionstring,
HostUser = _hostUsername,
HostEmail = _hostEmail,
Password = _hostPassword,
IsMaster = true,
};
Installation installation = await InstallationService.Install(config);
//TODO: Should be moved to Database manager
if (installation.Success)
{
Site site = new Site();
@ -208,4 +218,5 @@
_message = "<div class=\"alert alert-danger\" role=\"alert\">Please Enter All Fields And Ensure Passwords Match And Are Greater Than 5 Characters In Length</div>";
}
}
}