Skip to content

Commit 61af1be

Browse files
committed
DbUp
1 parent 3bd2236 commit 61af1be

File tree

9 files changed

+104
-23
lines changed

9 files changed

+104
-23
lines changed

Build.ps1

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function Exec
2323
}
2424

2525
if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse }
26+
if(Test-Path .\publish) { Remove-Item .\publish -Force -Recurse }
2627

2728

2829
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
@@ -31,39 +32,30 @@ $suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch
3132
$commitHash = $(git rev-parse --short HEAD)
3233
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]
3334

34-
exec { & .\tools\rh.exe /d=ContosoUniversity /f=ContosoUniversity\App_Data /s="(LocalDb)\mssqllocaldb" /silent }
35-
exec { & .\tools\rh.exe /d=ContosoUniversity-Test /f=ContosoUniversity\App_Data /s="(LocalDb)\mssqllocaldb" /silent /drop }
36-
exec { & .\tools\rh.exe /d=ContosoUniversity-Test /f=ContosoUniversity\App_Data /s="(LocalDb)\mssqllocaldb" /silent /simple }
37-
38-
3935
exec { & dotnet restore }
4036

4137
exec { & dotnet build -c Release --version-suffix=$buildSuffix }
4238

4339
Push-Location -Path .\ContosoUniversity.IntegrationTests
4440

4541
try {
46-
exec { & dotnet test -c Release --no-build }
42+
exec { & dotnet xunit -configuration Release -nobuild }
4743
}
4844
finally {
4945
Pop-Location
5046
}
5147

52-
#Push-Location -Path .\test\ContosoUniversity.UnitTests
48+
exec { & dotnet publish ContosoUniversity.Database --output .\..\publish\ContosoUniversity.Database --configuration Release }
5349

54-
#try {
55-
# exec { & dotnet test -c Release --no-build }
56-
#}
57-
#finally {
58-
# Pop-Location
59-
#}
50+
exec { & dotnet .\publish\ContosoUniversity.Database\ContosoUniversity.Database.dll }
6051

61-
exec { & dotnet publish ContosoUniversity --output .\..\publish --configuration Release }
52+
exec { & dotnet publish ContosoUniversity --output .\..\publish\ContosoUniversity --configuration Release }
6253

6354
$octo_revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = "0" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
6455
$octo_version = "1.0.$octo_revision"
6556

66-
exec { & .\tools\Octo.exe pack --id ContosoUniversity --version $octo_version --basePath publish --outFolder artifacts }
57+
exec { & .\tools\Octo.exe pack --id ContosoUniversity --version $octo_version --basePath publish\ContosoUniversity --outFolder artifacts }
58+
exec { & .\tools\Octo.exe pack --id ContosoUniversity.Database --version $octo_version --basePath publish\ContosoUniversity.Database --outFolder artifacts }
6759

6860

6961

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.0</TargetFramework>
6+
<LangVersion>latest</LangVersion>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<None Remove="Scripts\*.sql" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<EmbeddedResource Include="Scripts\*.sql" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<PackageReference Include="dbup-sqlserver" Version="4.0.0-beta0002" />
19+
</ItemGroup>
20+
21+
</Project>

ContosoUniversity.Database/Program.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Linq;
3+
using DbUp;
4+
5+
namespace ContosoUniversity.Database
6+
{
7+
public class Program
8+
{
9+
static int Main(string[] args)
10+
{
11+
var connectionString =
12+
args.FirstOrDefault()
13+
?? @"Server=(LocalDb)\mssqllocaldb; Database=ContosoUniversity; Trusted_connection=true";
14+
15+
var upgrader =
16+
DeployChanges.To
17+
.SqlDatabase(connectionString)
18+
.WithScriptsEmbeddedInAssembly(typeof(Program).Assembly, s => s.EndsWith(".sql"))
19+
.LogToConsole()
20+
.Build();
21+
22+
EnsureDatabase.For.SqlDatabase(connectionString);
23+
24+
var result = upgrader.PerformUpgrade();
25+
26+
if (!result.Successful)
27+
{
28+
Console.ForegroundColor = ConsoleColor.Red;
29+
Console.WriteLine(result.Error);
30+
Console.ResetColor();
31+
#if DEBUG
32+
Console.ReadLine();
33+
#endif
34+
return -1;
35+
}
36+
37+
Console.ForegroundColor = ConsoleColor.Green;
38+
Console.WriteLine("Success!");
39+
Console.ResetColor();
40+
return 0;
41+
}
42+
}
43+
}

ContosoUniversity.IntegrationTests/ContosoUniversity.IntegrationTests.csproj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" />
15-
<PackageReference Include="xunit" Version="2.3.0-beta4-build3742" />
16-
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta1-build3642" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170923-02" />
15+
<PackageReference Include="xunit" Version="2.3.0-rc2-build3812" />
16+
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-rc2-build3812" />
1717
<PackageReference Include="Shouldly" Version="3.0.0-beta0003" />
18-
<PackageReference Include="Respawn" Version="0.3.0" />
18+
<PackageReference Include="Respawn" Version="1.0.1" />
1919
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
2020
<PackageReference Include="FakeItEasy" Version="4.0.0" />
2121
<PackageReference Include="Microsoft.NETCore.Platforms" Version="2.0.0" />
22-
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta4-build3742" />
22+
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-rc2-build3812" />
23+
<PackageReference Include="dbup-sqlserver" Version="4.0.0-beta0002" />
2324
</ItemGroup>
2425

2526
<ItemGroup>
27+
<ProjectReference Include="..\ContosoUniversity.Database\ContosoUniversity.Database.csproj" />
2628
<ProjectReference Include="..\ContosoUniversity\ContosoUniversity.csproj" />
2729
</ItemGroup>
2830

ContosoUniversity.IntegrationTests/SliceFixture.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Threading.Tasks;
44
using ContosoUniversity.Data;
55
using ContosoUniversity.Models;
6+
using DbUp;
67
using FakeItEasy;
78
using MediatR;
89
using Microsoft.AspNetCore.Hosting;
@@ -38,6 +39,22 @@ static SliceFixture()
3839
var provider = services.BuildServiceProvider();
3940
_scopeFactory = provider.GetService<IServiceScopeFactory>();
4041
_checkpoint = new Checkpoint();
42+
43+
var connectionString = _configuration.GetConnectionString("DefaultConnection");
44+
45+
var upgrader =
46+
DeployChanges.To
47+
.SqlDatabase(connectionString)
48+
.WithScriptsEmbeddedInAssembly(typeof(ContosoUniversity.Database.Program).Assembly, s => s.EndsWith(".sql"))
49+
.LogToConsole()
50+
.Build();
51+
52+
EnsureDatabase.For.SqlDatabase(connectionString);
53+
54+
var result = upgrader.PerformUpgrade();
55+
56+
if (!result.Successful)
57+
throw result.Error;
4158
}
4259

4360
public static Task ResetCheckpoint() => _checkpoint.Reset(_configuration.GetConnectionString("DefaultConnection"));
205 KB
Binary file not shown.

ContosoUniversity.sln

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26730.8
4+
VisualStudioVersion = 15.0.26730.10
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ContosoUniversity", "ContosoUniversity\ContosoUniversity.csproj", "{DDBC05AD-34FD-43B7-B0D1-45819DEC4AA1}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ContosoUniversity.IntegrationTests", "ContosoUniversity.IntegrationTests\ContosoUniversity.IntegrationTests.csproj", "{70FF0FF8-4876-4A7A-AE4A-53C92A2C1531}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ContosoUniversity.IntegrationTests", "ContosoUniversity.IntegrationTests\ContosoUniversity.IntegrationTests.csproj", "{70FF0FF8-4876-4A7A-AE4A-53C92A2C1531}"
99
EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{13186C93-7307-4FEA-A17C-4556F54FF5F1}"
1111
ProjectSection(SolutionItems) = preProject
@@ -15,6 +15,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1515
README.md = README.md
1616
EndProjectSection
1717
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ContosoUniversity.Database", "ContosoUniversity.Database\ContosoUniversity.Database.csproj", "{FA552E39-B5B0-46E3-822D-AD0976D938BA}"
19+
EndProject
1820
Global
1921
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2022
Debug|Any CPU = Debug|Any CPU
@@ -29,6 +31,10 @@ Global
2931
{70FF0FF8-4876-4A7A-AE4A-53C92A2C1531}.Debug|Any CPU.Build.0 = Debug|Any CPU
3032
{70FF0FF8-4876-4A7A-AE4A-53C92A2C1531}.Release|Any CPU.ActiveCfg = Release|Any CPU
3133
{70FF0FF8-4876-4A7A-AE4A-53C92A2C1531}.Release|Any CPU.Build.0 = Release|Any CPU
34+
{FA552E39-B5B0-46E3-822D-AD0976D938BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35+
{FA552E39-B5B0-46E3-822D-AD0976D938BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
36+
{FA552E39-B5B0-46E3-822D-AD0976D938BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
37+
{FA552E39-B5B0-46E3-822D-AD0976D938BA}.Release|Any CPU.Build.0 = Release|Any CPU
3238
EndGlobalSection
3339
GlobalSection(SolutionProperties) = preSolution
3440
HideSolutionNode = FALSE

ContosoUniversity/ContosoUniversity.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<ItemGroup>
1515
<PackageReference Include="AutoMapper" Version="6.1.1" />
1616
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="3.0.1" />
17-
<PackageReference Include="FluentValidation.AspNetCore" Version="7.2.0-beta2" />
17+
<PackageReference Include="FluentValidation.AspNetCore" Version="7.2.0-beta3" />
1818
<PackageReference Include="HtmlTags.AspNetCore" Version="5.0.2" />
1919
<!--<PackageReference Include="HtmlTags.AspNetCore" Version="5.0.0" />-->
2020
<PackageReference Include="MediatR" Version="3.0.1" />

0 commit comments

Comments
 (0)