1
1
using System ;
2
- using System . Diagnostics ;
3
- using System . Reflection ;
4
- using DbUp ;
5
- using DbUp . Engine ;
6
- using DbUp . SQLite . Helpers ;
7
2
8
3
namespace SQLiteSampleApplication
9
4
{
10
- class Program
5
+ public static class Program
11
6
{
12
7
static void Main ( )
13
8
{
14
- using ( var database = new TemporarySQLiteDatabase ( "test" ) )
15
- {
16
- database . Create ( ) ;
9
+ InMemoryDb ( ) ;
10
+ TemporaryFileDb ( ) ;
11
+ PermanentFileDb ( ) ;
12
+ }
17
13
14
+ static void InMemoryDb ( )
15
+ {
16
+ using ( var database = new DbUp . SQLite . Helpers . InMemorySQLiteDatabase ( ) )
17
+ {
18
18
var upgrader =
19
- DeployChanges . To
20
- . SQLiteDatabase ( database . SharedConnection )
21
- . WithScriptsEmbeddedInAssembly ( Assembly . GetExecutingAssembly ( ) )
22
- . LogToConsole ( )
23
- . Build ( ) ;
19
+ DbUp . DeployChanges . To
20
+ . SQLiteDatabase ( database . ConnectionString )
21
+ . WithScriptsEmbeddedInAssembly ( System . Reflection . Assembly . GetExecutingAssembly ( ) )
22
+ . LogToConsole ( )
23
+ . Build ( ) ;
24
+
25
+ var watch = new System . Diagnostics . Stopwatch ( ) ;
24
26
25
- var watch = new Stopwatch ( ) ;
26
27
watch . Start ( ) ;
28
+ DbUp . Engine . DatabaseUpgradeResult result = upgrader . PerformUpgrade ( ) ;
29
+ watch . Stop ( ) ;
27
30
28
- var result = upgrader . PerformUpgrade ( ) ;
31
+ Display ( "InMemory" , result , watch . Elapsed ) ;
32
+ } // Database will be deleted at this point
33
+ }
29
34
35
+ static void TemporaryFileDb ( )
36
+ {
37
+ using ( var database = new DbUp . SQLite . Helpers . TemporarySQLiteDatabase ( "test.db" ) )
38
+ {
39
+ var upgrader =
40
+ DbUp . DeployChanges . To
41
+ . SQLiteDatabase ( database . SharedConnection )
42
+ . WithScriptsEmbeddedInAssembly ( System . Reflection . Assembly . GetExecutingAssembly ( ) )
43
+ . LogToConsole ( )
44
+ . Build ( ) ;
45
+
46
+ var watch = new System . Diagnostics . Stopwatch ( ) ;
47
+
48
+ watch . Start ( ) ;
49
+ DbUp . Engine . DatabaseUpgradeResult result = upgrader . PerformUpgrade ( ) ;
30
50
watch . Stop ( ) ;
31
- Display ( "File" , result , watch . Elapsed ) ;
51
+
52
+ Display ( "Temporary file" , result , watch . Elapsed ) ;
32
53
} // Database will be deleted at this point
54
+ }
55
+
56
+ static void PermanentFileDb ( )
57
+ {
58
+ Microsoft . Data . Sqlite . SqliteConnection connection = new ( "Data Source=dbup.db" ) ;
33
59
34
- using ( var database = new InMemorySQLiteDatabase ( ) )
60
+ using ( var database = new DbUp . SQLite . Helpers . SharedConnection ( connection ) )
35
61
{
36
- var upgrader =
37
- DeployChanges . To
38
- . SQLiteDatabase ( database . ConnectionString )
39
- . WithScriptsEmbeddedInAssembly ( Assembly . GetExecutingAssembly ( ) )
62
+ var upgrader = DbUp . DeployChanges
63
+ . To
64
+ . SQLiteDatabase ( connection . ConnectionString )
65
+ . WithScriptsEmbeddedInAssembly ( System . Reflection . Assembly . GetExecutingAssembly ( ) )
40
66
. LogToConsole ( )
41
67
. Build ( ) ;
42
68
43
- var watch = new Stopwatch ( ) ;
44
- watch . Start ( ) ;
45
-
46
- var result = upgrader . PerformUpgrade ( ) ;
69
+ var watch = new System . Diagnostics . Stopwatch ( ) ;
47
70
71
+ watch . Start ( ) ;
72
+ DbUp . Engine . DatabaseUpgradeResult result = upgrader . PerformUpgrade ( ) ;
48
73
watch . Stop ( ) ;
49
- Display ( "InMemory" , result , watch . Elapsed ) ;
50
- } // Database will disappear from memory at this point
74
+
75
+ Display ( "Permanent file" , result , watch . Elapsed ) ;
76
+ } // Database will NOT be deleted at this point
51
77
}
52
78
53
- static void Display ( string dbType , DatabaseUpgradeResult result , TimeSpan ts )
79
+ static void Display ( string dbType , DbUp . Engine . DatabaseUpgradeResult result , TimeSpan ts )
54
80
{
55
81
// Display the result
56
82
if ( result . Successful )
57
83
{
58
84
Console . ForegroundColor = ConsoleColor . Green ;
59
85
Console . WriteLine ( "Success!" ) ;
60
- Console . WriteLine ( "{0} Database Upgrade Runtime: {1}" , dbType ,
86
+ Console . WriteLine (
87
+ "{0} Database Upgrade Runtime: {1}" ,
88
+ dbType ,
61
89
string . Format ( "{0:00}:{1:00}:{2:00}.{3:00}" , ts . Hours , ts . Minutes , ts . Seconds , ts . Milliseconds / 10 ) ) ;
62
90
Console . ReadKey ( ) ;
63
91
}
@@ -70,4 +98,4 @@ static void Display(string dbType, DatabaseUpgradeResult result, TimeSpan ts)
70
98
}
71
99
}
72
100
}
73
- }
101
+ }
0 commit comments