29 lines
1007 B
C#
29 lines
1007 B
C#
using System;
|
|
using System.IO;
|
|
using System.Text.RegularExpressions;
|
|
using Microsoft.Data.SqlClient;
|
|
|
|
var connectionString = "Server=localhost;Database=PlotLine;User Id=PlotLineApp;Password=t6eb1cvd9bNB27czde#h9r;MultipleActiveResultSets=true;Encrypt=false;";
|
|
var scriptPath = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..", "..", "..", "..", "..", "PlotLine", "Sql", "026_TimelineConfigurationSettings.sql"));
|
|
var script = await File.ReadAllTextAsync(scriptPath);
|
|
var batches = Regex.Split(script, @"^\s*GO\s*$", RegexOptions.Multiline | RegexOptions.IgnoreCase);
|
|
|
|
await using var connection = new SqlConnection(connectionString);
|
|
await connection.OpenAsync();
|
|
|
|
var count = 0;
|
|
foreach (var batch in batches)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(batch))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
await using var command = new SqlCommand(batch, connection);
|
|
command.CommandTimeout = 120;
|
|
await command.ExecuteNonQueryAsync();
|
|
count++;
|
|
}
|
|
|
|
Console.WriteLine($"Applied {count} SQL batches.");
|