-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathProgram.cs
More file actions
104 lines (89 loc) · 3.66 KB
/
Program.cs
File metadata and controls
104 lines (89 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using Microsoft.Data.Sqlite;
namespace SqliteSampleApplication
{
public static class Program
{
static void Main()
{
//InMemoryDb();
//TemporaryFileDb();
PermanentFileDb();
}
static void InMemoryDb()
{
using (var database = new DbUp.Sqlite.Helpers.InMemorySqliteDatabase())
{
var upgrader =
DbUp.DeployChanges.To
.SqliteDatabase(database.ConnectionString)
.WithScriptsEmbeddedInAssembly(System.Reflection.Assembly.GetExecutingAssembly())
.LogToConsole()
.Build();
var watch = new System.Diagnostics.Stopwatch();
watch.Start();
DbUp.Engine.DatabaseUpgradeResult result = upgrader.PerformUpgrade();
watch.Stop();
Display("InMemory", result, watch.Elapsed);
} // Database will be deleted at this point
}
static void TemporaryFileDb()
{
using (var database = new DbUp.Sqlite.Helpers.TemporarySqliteDatabase("test.db"))
{
var upgrader =
DbUp.DeployChanges.To
.SqliteDatabase(database.SharedConnection)
.WithScriptsEmbeddedInAssembly(System.Reflection.Assembly.GetExecutingAssembly())
.LogToConsole()
.Build();
var watch = new System.Diagnostics.Stopwatch();
watch.Start();
DbUp.Engine.DatabaseUpgradeResult result = upgrader.PerformUpgrade();
watch.Stop();
Display("Temporary file", result, watch.Elapsed);
} // Database will be deleted at this point
}
static void PermanentFileDb()
{
SqliteConnection connection = new("Data Source=dbup.db;");
using (var database = new DbUp.Sqlite.Helpers.SharedConnection(connection))
{
var upgrader = DbUp.DeployChanges
.To
.SqliteDatabase(connection.ConnectionString)
.WithScriptsEmbeddedInAssembly(System.Reflection.Assembly.GetExecutingAssembly())
.LogToConsole()
.Build();
var watch = new System.Diagnostics.Stopwatch();
watch.Start();
DbUp.Engine.DatabaseUpgradeResult result = upgrader.PerformUpgrade();
watch.Stop();
Display("Permanent file", result, watch.Elapsed);
} // Database will NOT be deleted at this point
}
static void Display(string dbType, DbUp.Engine.DatabaseUpgradeResult result, TimeSpan ts)
{
// Display the result
if (result.Successful)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Success!");
Console.WriteLine(
"{0} Database Upgrade Runtime: {1}",
dbType,
string.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10));
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(result.Error);
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
Console.WriteLine("Failed!");
}
}
}
}