/// <summary> /// Applies the given single sql file /// </summary> /// <param name="db"></param> /// <param name="filePath"></param> /// <returns></returns> public async static Task <bool> ApplySQLFile(this DbContext db, string filePath, bool hashSumTracking = true, int timeOut = 60, bool debugOutput = false) { if (timeOut <= 0) { timeOut = 60; } Constants.DebugOutput = debugOutput; Constants.SQLTimeout = timeOut; Constants.HashSumTracking = hashSumTracking; string ext = Path.GetExtension(filePath); if (ext != ".sql") { if (debugOutput) { Console.WriteLine($"{filePath} is not an sql file!"); } return(false); } if (!File.Exists(filePath)) { if (debugOutput) { Console.WriteLine($"Could not locate file {filePath}!"); } return(false); } try { string content = File.ReadAllText(filePath); // Check for emtpy file if (string.IsNullOrWhiteSpace(content)) { if (debugOutput) { Console.WriteLine($"{filePath} has empty content!"); } return(false); } // Check if hashSumTracking is deactivated if (!hashSumTracking) { await MySqlUpdater.ExecuteQuery(db, content); return(true); } if (!await MySqlUpdater.IsUpdatesTableAvailable(db)) { Console.WriteLine("No updates table detected! Aborting! Please use CreateUpdatesTable() to create the required table or set hashSumTracking = false."); return(false); } if (debugOutput) { Console.WriteLine($"Applying {Path.GetFileName(filePath)}"); } TimeSpan ts = await MySqlUpdater.ExecuteQuery(db, content); await MySqlUpdater.InsertHash(db, filePath); return(true); } catch { throw; } }