MigrationService fix

messaging
Tudor Stanciu 2022-01-22 01:54:19 +02:00
parent f5bf32e285
commit 92632050d7
6 changed files with 12 additions and 12 deletions

View File

@ -1,6 +1,7 @@
{ {
"ConnectionStrings": { "ConnectionStrings": {
"DatabaseConnection": "Data Source={Workspace}\\TesterDb.db" "DatabaseConnection": "Data Source={Workspace}\\TesterDb.db"
//"DatabaseConnection": "***REMOVED***"
}, },
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {

View File

@ -7,7 +7,7 @@
<RepositoryUrl>https://dev.azure.com/tstanciu94/NDB</RepositoryUrl> <RepositoryUrl>https://dev.azure.com/tstanciu94/NDB</RepositoryUrl>
<RepositoryType>Git</RepositoryType> <RepositoryType>Git</RepositoryType>
<PackageTags>NDB Database migration</PackageTags> <PackageTags>NDB Database migration</PackageTags>
<Version>1.0.1</Version> <Version>1.0.2</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -4,6 +4,6 @@ namespace NDB.Infrastructure.DatabaseMigration.Repositories
{ {
public interface IMigrationRepository public interface IMigrationRepository
{ {
Task ExecuteSqlRaw(string commandText); Task ExecuteSqlRaw(string sqlRaw);
} }
} }

View File

@ -13,14 +13,9 @@ namespace NDB.Infrastructure.DatabaseMigration.Repositories
_dbContext = dbContext; _dbContext = dbContext;
} }
public async Task ExecuteSqlRaw(string commandText) public async Task ExecuteSqlRaw(string sqlRaw)
{ {
using (var command = _dbContext.Database.GetDbConnection().CreateCommand()) await _dbContext.Database.ExecuteSqlRawAsync(sqlRaw);
{
command.CommandText = commandText;
await _dbContext.Database.OpenConnectionAsync();
await command.ExecuteNonQueryAsync();
}
} }
} }
} }

View File

@ -6,6 +6,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using System.Xml; using System.Xml;
using System.Xml.Serialization; using System.Xml.Serialization;
@ -112,6 +113,9 @@ namespace NDB.Infrastructure.DatabaseMigration.Services
} }
private void RunScript(string path) private void RunScript(string path)
=> RunScriptAsync(path).GetAwaiter().GetResult();
private async Task RunScriptAsync(string path)
{ {
_logger.LogInformation($"Running sql script: '{path}'"); _logger.LogInformation($"Running sql script: '{path}'");
var sqlContent = File.ReadAllText(path); var sqlContent = File.ReadAllText(path);
@ -121,7 +125,7 @@ namespace NDB.Infrastructure.DatabaseMigration.Services
using (var scope = _serviceProvider.CreateScope()) using (var scope = _serviceProvider.CreateScope())
{ {
var _repository = scope.ServiceProvider.GetRequiredService<IMigrationRepository>(); var _repository = scope.ServiceProvider.GetRequiredService<IMigrationRepository>();
_repository.ExecuteSqlRaw(sqlContent); await _repository.ExecuteSqlRaw(sqlContent);
} }
} }
} }

View File

@ -3,11 +3,11 @@
"Code" TEXT NOT NULL UNIQUE, "Code" TEXT NOT NULL UNIQUE,
"Name" TEXT NOT NULL, "Name" TEXT NOT NULL,
"Description" TEXT, "Description" TEXT,
"Context" TEXT NOT NULL "Context" TEXT NOT NULL,
CONSTRAINT "PK_Settings" PRIMARY KEY("Id" AUTOINCREMENT) CONSTRAINT "PK_Settings" PRIMARY KEY("Id" AUTOINCREMENT)
); );
INSERT INTO Settings(Id, Code, Name, Context) INSERT INTO Settings(Id, Code, Name, Context)
SELECT 1, 'THEME', 'Application theme', 'USER' UNION SELECT 1, 'THEME', 'Application theme', 'USER' UNION
SELECT 2, 'LANGUAGE', 'Application language', 'USER' UNION SELECT 2, 'LANGUAGE', 'Application language', 'USER' UNION
SELECT 3, 'NOTIFICATIONS_POSITION', 'Notifications position', 'USER' SELECT 3, 'NOTIFICATIONS_POSITION', 'Notifications position', 'USER';