Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 95cedb3

Browse files
committed
added database deployment
1 parent fadef5d commit 95cedb3

File tree

5 files changed

+63
-2
lines changed

5 files changed

+63
-2
lines changed

‎.gitignore‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,5 +272,4 @@ __blobstorage__/
272272
.env.v*
273273
global.json
274274
log.txt
275-
/database/
276275
client/dist/

‎cleanup.v2.sh‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ rm -rf ./client/dist
1717
echo "Cleaning ./database ..."
1818
rm -rf ./database/declarative-deploy
1919
rm -rf ./database/imperative-deploy
20-
rm -rf ./database/deploy
20+
rm -rf ./database/deploy/bin
21+
rm -rf ./database/deploy/obj
2122

2223
# cleanup TEST
2324
echo "Cleaning ./test ..."

‎database/deploy/.env.template‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ConnectionString="Server=.database.windows.net;Initial Catalog=;User ID=;Password=;Encrypt=true;"

‎database/deploy/Program.cs‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using DbUp;
3+
using DotNetEnv;
4+
using Microsoft.Data.SqlClient;
5+
6+
namespace Todo.Database.Deploy
7+
{
8+
class Program
9+
{
10+
static int Main(string[] args)
11+
{
12+
// This will load the content of .env file and create related environment variables
13+
DotNetEnv.Env.Load();
14+
15+
// Connection string for deploying the database (high-privileged account as it needs to be able to CREATE/ALTER/DROP)
16+
var connectionString = Environment.GetEnvironmentVariable("ConnectionString");
17+
18+
var csb = new SqlConnectionStringBuilder(connectionString);
19+
Console.WriteLine($"Deploying database: {csb.InitialCatalog}");
20+
21+
Console.WriteLine("Testing connection...");
22+
var conn = new SqlConnection(csb.ToString());
23+
conn.Open();
24+
conn.Close();
25+
26+
Console.WriteLine("Starting deployment...");
27+
var dbup = DeployChanges.To
28+
.SqlDatabase(csb.ConnectionString)
29+
.WithScriptsFromFileSystem("../sql")
30+
.JournalToSqlTable("dbo", "$__dbup_journal")
31+
.LogToConsole()
32+
.Build();
33+
34+
var result = dbup.PerformUpgrade();
35+
36+
if (!result.Successful)
37+
{
38+
Console.WriteLine(result.Error);
39+
return -1;
40+
}
41+
42+
Console.WriteLine("Success!");
43+
return 0;
44+
}
45+
}
46+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="DbUp" Version="4.5.0" />
10+
<PackageReference Include="DotNetEnv" Version="2.3.0" />
11+
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.1.0" />
12+
</ItemGroup>
13+
14+
</Project>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /