AppDbContext: Add ExecuteEmbeddedScript()
This commit is contained in:
		@@ -1,7 +1,6 @@
 | 
			
		||||
using Microsoft.Data.Sqlite;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
@@ -44,7 +43,7 @@ namespace Elwig.Helpers {
 | 
			
		||||
 | 
			
		||||
        private static async Task UpdateDbSchema(SqliteConnection cnx, int fromVersion, int toVersion) {
 | 
			
		||||
            if (fromVersion == toVersion) {
 | 
			
		||||
                //return;
 | 
			
		||||
                return;
 | 
			
		||||
            } else if (fromVersion > toVersion) {
 | 
			
		||||
                throw new Exception("schema_version of database is too new");
 | 
			
		||||
            } else if (fromVersion <= 0) {
 | 
			
		||||
@@ -77,9 +76,7 @@ namespace Elwig.Helpers {
 | 
			
		||||
                BEGIN EXCLUSIVE;
 | 
			
		||||
                """);
 | 
			
		||||
            foreach (var script in toExecute) {
 | 
			
		||||
                using var stream = asm.GetManifestResourceStream(script) ?? throw new Exception("Unable to load embedded resource");
 | 
			
		||||
                using var reader = new StreamReader(stream);
 | 
			
		||||
                await AppDbContext.ExecuteBatch(cnx, await reader.ReadToEndAsync());
 | 
			
		||||
                await AppDbContext.ExecuteEmbeddedScript(cnx, asm, script);
 | 
			
		||||
            }
 | 
			
		||||
            await AppDbContext.ExecuteBatch(cnx, $"""
 | 
			
		||||
                PRAGMA foreign_key_check;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user