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": {
"DatabaseConnection": "Data Source={Workspace}\\TesterDb.db"
//"DatabaseConnection": "***REMOVED***"
},
"Logging": {
"LogLevel": {

View File

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

View File

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

View File

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

View File

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

View File

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