Skip to content

Commit

Permalink
Converted SampleApplication and used new DropDatabase functionality i…
Browse files Browse the repository at this point in the history
…n it
  • Loading branch information
droyad committed Feb 17, 2018
1 parent d161df4 commit fafe79c
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 182 deletions.
11 changes: 11 additions & 0 deletions src/DbUp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dbup-tests", "dbup-tests\db
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dbup-sqlite-mono", "dbup-sqlite-mono\dbup-sqlite-mono.csproj", "{CD122205-EEC4-4DB9-9EFA-976EADF80323}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{ACA9F575-BFC0-4FE1-BAB6-AE59FD8E5C26}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleApplication", "Samples\SampleApplication\SampleApplication.csproj", "{397F41BC-1076-4D1B-9620-C6051E8104F4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -75,6 +79,10 @@ Global
{CD122205-EEC4-4DB9-9EFA-976EADF80323}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CD122205-EEC4-4DB9-9EFA-976EADF80323}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CD122205-EEC4-4DB9-9EFA-976EADF80323}.Release|Any CPU.Build.0 = Release|Any CPU
{397F41BC-1076-4D1B-9620-C6051E8104F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{397F41BC-1076-4D1B-9620-C6051E8104F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{397F41BC-1076-4D1B-9620-C6051E8104F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{397F41BC-1076-4D1B-9620-C6051E8104F4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -85,4 +93,7 @@ Global
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = DbUp\DbUp.csproj
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{397F41BC-1076-4D1B-9620-C6051E8104F4} = {ACA9F575-BFC0-4FE1-BAB6-AE59FD8E5C26}
EndGlobalSection
EndGlobal
83 changes: 43 additions & 40 deletions src/Samples/SampleApplication/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,58 @@ public static void Main(string[] args)
// Uncomment the following line to run against sql local db instance.
// string instanceName = @"(localdb)\Projects";

using (var database = new TemporarySqlDatabase("SampleApplication", instanceName))
{
database.Create();
var connectionString =
$"Data Source={instanceName};Initial Catalog=SampleApplication;Integrated Security=True;Pooling=False";

var upgradeEngineBuilder = DeployChanges.To
.SqlDatabase(database.ConnectionString, null) //null or "" for default schema for user
.WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly(), script =>
{
if (script.EndsWith("Script0006 - Transactions.sql"))
return !args.Any(a => "--noError".Equals(a, StringComparison.InvariantCultureIgnoreCase));
DropDatabase.For.SqlDatabase(connectionString);

return true;
})
.LogToConsole();
EnsureDatabase.For.SqlDatabase(connectionString);

var upgradeEngineBuilder = DeployChanges.To
.SqlDatabase(connectionString, null) //null or "" for default schema for user
.WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly(), script =>
{
if (script.EndsWith("Script0006 - Transactions.sql"))
return !args.Any(a => "--noError".Equals(a, StringComparison.InvariantCultureIgnoreCase));

if (args.Any(a => "--withTransaction".Equals(a, StringComparison.InvariantCultureIgnoreCase)))
upgradeEngineBuilder = upgradeEngineBuilder.WithTransaction();
else if (args.Any(a => "--withTransactionPerScript".Equals(a, StringComparison.InvariantCultureIgnoreCase)))
upgradeEngineBuilder = upgradeEngineBuilder.WithTransactionPerScript();
return true;
})
.LogToConsole();

var upgrader = upgradeEngineBuilder.Build();
if (args.Any(a => "--withTransaction".Equals(a, StringComparison.InvariantCultureIgnoreCase)))
upgradeEngineBuilder = upgradeEngineBuilder.WithTransaction();
else if (args.Any(a => "--withTransactionPerScript".Equals(a, StringComparison.InvariantCultureIgnoreCase)))
upgradeEngineBuilder = upgradeEngineBuilder.WithTransactionPerScript();

Console.WriteLine("Is upgrade required: " + upgrader.IsUpgradeRequired());
var upgrader = upgradeEngineBuilder.Build();

var result = upgrader.PerformUpgrade();
Console.WriteLine("Is upgrade required: " + upgrader.IsUpgradeRequired());

// Display the result
if (result.Successful)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Success!");
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(result.Error);
Console.WriteLine("Failed!");
}
var result = upgrader.PerformUpgrade();

Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine();
Console.WriteLine("Press any key to delete your database and continue");
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Try the --withTransaction or --withTransactionPerScript to see transaction support in action");
Console.WriteLine("--noError to exclude the broken script");
Console.ReadKey();
// Database will be deleted at this point
// Display the result
if (result.Successful)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Success!");
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(result.Error);
Console.WriteLine("Failed!");
}

Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine();
Console.WriteLine("Press any key to delete your database and continue");
Console.WriteLine();
Console.WriteLine();
Console.WriteLine(
"Try the --withTransaction or --withTransactionPerScript to see transaction support in action");
Console.WriteLine("--noError to exclude the broken script");
Console.ReadKey();
// Database will be deleted at this point
}
}
}
36 changes: 0 additions & 36 deletions src/Samples/SampleApplication/Properties/AssemblyInfo.cs

This file was deleted.

74 changes: 6 additions & 68 deletions src/Samples/SampleApplication/SampleApplication.csproj
Original file line number Diff line number Diff line change
@@ -1,76 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{83042F56-9FAD-4827-B542-6873F93D7940}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
<RootNamespace>SampleApplication</RootNamespace>
<AssemblyName>SampleApplication</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject>SampleApplication.Program</StartupObject>
<AssemblyName>SampleApplication</AssemblyName>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\DbUp.SqlServer\DbUp.SqlServer.csproj">
<Project>{ee71e015-3442-45b3-97b6-7886b7de8351}</Project>
<Name>DbUp.SqlServer</Name>
</ProjectReference>
<ProjectReference Include="..\..\DbUp.Core\DbUp.Core.csproj">
<Project>{2D2C117A-7841-4285-A4CE-E7C4FC64AD9B}</Project>
<Name>DbUp.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Scripts\Script0001 - Create tables.sql" />
<EmbeddedResource Include="Scripts\Script0002 - Default feed.sql" />
<EmbeddedResource Include="Scripts\Script0003 - Settings.sql" />
<EmbeddedResource Include="Scripts\Script0004 - Redirects.sql" />
</ItemGroup>
<ItemGroup>
<Compile Include="Scripts\Script0005 - ComplexUpdate.cs" />
<ProjectReference Include="..\..\dbup-sqlserver\dbup-sqlserver.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Scripts\Script0006 - Transactions.sql" />
<EmbeddedResource Include="Scripts\*.sql" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
19 changes: 0 additions & 19 deletions src/Samples/SampleApplication/SampleApplication.ncrunchproject

This file was deleted.

19 changes: 0 additions & 19 deletions src/Samples/SampleApplication/SampleApplication.v2.ncrunchproject

This file was deleted.

0 comments on commit fafe79c

Please sign in to comment.