Added suuport to inject an IOqtaneDatabase in EntityBuilders to allow each Database to control certain Migration behaviors. Also updated Installer to dynamically build Database Configuration section
This commit is contained in:
@ -1,17 +1,61 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Oqtane.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Repository.Databases;
|
||||
|
||||
namespace Oqtane.Repository.Databases
|
||||
// ReSharper disable ArrangeObjectCreationWhenTypeNotEvident
|
||||
|
||||
namespace Oqtane.Databases
|
||||
{
|
||||
public class SqlServerDatabase : IDatabase
|
||||
public class SqlServerDatabase : SqlServerDatabaseBase
|
||||
{
|
||||
public string FriendlyName => "SQL Server";
|
||||
private static string _friendlyName => "SQL Server";
|
||||
private static string _name => "SqlServer";
|
||||
|
||||
public string Name => "SqlServer";
|
||||
|
||||
public DbContextOptionsBuilder UseDatabase(DbContextOptionsBuilder optionsBuilder, string connectionString)
|
||||
private static readonly List<ConnectionStringField> _connectionStringFields = new()
|
||||
{
|
||||
return optionsBuilder.UseSqlServer(connectionString);
|
||||
new() {Name = "Server", FriendlyName = "Server", Value = "."},
|
||||
new() {Name = "Database", FriendlyName = "Database", Value = "Oqtane-{{Date}}"},
|
||||
new() {Name = "IntegratedSecurity", FriendlyName = "Integrated Security", Value = "true"},
|
||||
new() {Name = "Uid", FriendlyName = "User Id", Value = ""},
|
||||
new() {Name = "Pwd", FriendlyName = "Password", Value = ""}
|
||||
};
|
||||
|
||||
public SqlServerDatabase() :base(_name, _friendlyName, _connectionStringFields) { }
|
||||
|
||||
public override string BuildConnectionString()
|
||||
{
|
||||
var connectionString = String.Empty;
|
||||
|
||||
var server = ConnectionStringFields[0].Value;
|
||||
var database = ConnectionStringFields[1].Value;
|
||||
var integratedSecurity = Boolean.Parse(ConnectionStringFields[2].Value);
|
||||
var userId = ConnectionStringFields[3].Value;
|
||||
var password = ConnectionStringFields[4].Value;
|
||||
|
||||
if (!String.IsNullOrEmpty(server) && !String.IsNullOrEmpty(database))
|
||||
{
|
||||
connectionString = $"Data Source={server};Initial Catalog={database};";
|
||||
}
|
||||
|
||||
if (integratedSecurity)
|
||||
{
|
||||
connectionString += "Integrated Security=SSPI;";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.IsNullOrEmpty(userId) && !String.IsNullOrEmpty(password))
|
||||
{
|
||||
connectionString += $"User ID={userId};Password={password};";
|
||||
}
|
||||
else
|
||||
{
|
||||
connectionString = String.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
return connectionString;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user