Commit 03fec6db authored by L. Ellenbeck's avatar L. Ellenbeck Committed by Marcel Nellesen
Browse files

Update: Adapt Migrations for the database project

parent ef548374
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit3TestAdapter.3.17.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.17.0\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\packages\NUnit.3.12.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6A8B7CA4-F59C-47EC-A6E9-D5AAA69D5BB1}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Migrations.Tests</RootNamespace>
<AssemblyName>Migrations.Tests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</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>
<ItemGroup>
<Reference Include="Consul, Version=0.7.2.6, Culture=neutral, PublicKeyToken=20a6ad9a81df1d95, processorArchitecture=MSIL">
<HintPath>..\packages\Consul.0.7.2.6\lib\net45\Consul.dll</HintPath>
</Reference>
<Reference Include="Coscine.Configuration, Version=1.5.0.0, Culture=neutral, PublicKeyToken=ce3d7a32d7dc1e5a, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Configuration.1.5.0\lib\net461\Coscine.Configuration.dll</HintPath>
</Reference>
<Reference Include="Coscine.Database.Helpers, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Database.Helpers.1.1.0-topic-894-automa0005\lib\net461\Coscine.Database.Helpers.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.3.2.8\lib\net461\FluentMigrator.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Abstractions, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Abstractions.3.2.8\lib\net461\FluentMigrator.Abstractions.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Extensions.Oracle, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Extensions.Oracle.3.2.8\lib\net461\FluentMigrator.Extensions.Oracle.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Extensions.Postgres, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Extensions.Postgres.3.2.8\lib\net461\FluentMigrator.Extensions.Postgres.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Extensions.SqlAnywhere, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Extensions.SqlAnywhere.3.2.8\lib\net461\FluentMigrator.Extensions.SqlAnywhere.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Extensions.SqlServer, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Extensions.SqlServer.3.2.8\lib\net461\FluentMigrator.Extensions.SqlServer.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Runner, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Runner.3.2.8\lib\net461\FluentMigrator.Runner.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Runner.Core, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Runner.Core.3.2.8\lib\net461\FluentMigrator.Runner.Core.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Runner.Db2, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Runner.Db2.3.2.8\lib\net461\FluentMigrator.Runner.Db2.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Runner.Firebird, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Runner.Firebird.3.2.8\lib\net461\FluentMigrator.Runner.Firebird.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Runner.Hana, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Runner.Hana.3.2.8\lib\net461\FluentMigrator.Runner.Hana.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Runner.Jet, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Runner.Jet.3.2.8\lib\net461\FluentMigrator.Runner.Jet.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Runner.MySql, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Runner.MySql.3.2.8\lib\net461\FluentMigrator.Runner.MySql.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Runner.Oracle, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Runner.Oracle.3.2.8\lib\net461\FluentMigrator.Runner.Oracle.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Runner.Postgres, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Runner.Postgres.3.2.8\lib\net461\FluentMigrator.Runner.Postgres.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Runner.Redshift, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Runner.Redshift.3.2.8\lib\net461\FluentMigrator.Runner.Redshift.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Runner.SqlAnywhere, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Runner.SqlAnywhere.3.2.8\lib\net461\FluentMigrator.Runner.SqlAnywhere.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Runner.SQLite, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Runner.SQLite.3.2.8\lib\net461\FluentMigrator.Runner.SQLite.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Runner.SqlServer, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Runner.SqlServer.3.2.8\lib\net461\FluentMigrator.Runner.SqlServer.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Runner.SqlServerCe, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.Runner.SqlServerCe.3.2.8\lib\net461\FluentMigrator.Runner.SqlServerCe.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.Sqlite, Version=3.1.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Data.Sqlite.Core.3.1.5\lib\netstandard2.0\Microsoft.Data.Sqlite.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Configuration.Abstractions, Version=2.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Configuration.Abstractions.2.0.1\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.2.0.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.0.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Logging, Version=2.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Logging.2.0.1\lib\netstandard2.0\Microsoft.Extensions.Logging.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=2.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.2.0.1\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Options, Version=2.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Options.2.0.1\lib\netstandard2.0\Microsoft.Extensions.Options.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Primitives, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Primitives.2.0.0\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="SQLitePCLRaw.batteries_v2, Version=2.0.2.669, Culture=neutral, PublicKeyToken=8226ea5df37bcae9, processorArchitecture=MSIL">
<HintPath>..\packages\SQLitePCLRaw.bundle_e_sqlite3.2.0.2\lib\net461\SQLitePCLRaw.batteries_v2.dll</HintPath>
</Reference>
<Reference Include="SQLitePCLRaw.core, Version=2.0.2.669, Culture=neutral, PublicKeyToken=1488e028ca7ab535, processorArchitecture=MSIL">
<HintPath>..\packages\SQLitePCLRaw.core.2.0.2\lib\netstandard2.0\SQLitePCLRaw.core.dll</HintPath>
</Reference>
<Reference Include="SQLitePCLRaw.nativelibrary, Version=2.0.2.669, Culture=neutral, PublicKeyToken=502ed628492ab262, processorArchitecture=MSIL">
<HintPath>..\packages\SQLitePCLRaw.bundle_e_sqlite3.2.0.2\lib\net461\SQLitePCLRaw.nativelibrary.dll</HintPath>
</Reference>
<Reference Include="SQLitePCLRaw.provider.dynamic_cdecl, Version=2.0.2.669, Culture=neutral, PublicKeyToken=b68184102cba0b3b, processorArchitecture=MSIL">
<HintPath>..\packages\SQLitePCLRaw.provider.dynamic_cdecl.2.0.2\lib\netstandard2.0\SQLitePCLRaw.provider.dynamic_cdecl.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.ComponentModel.Annotations.4.4.1\lib\net461\System.ComponentModel.Annotations.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MigrationsTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Migrations\Migrations.csproj">
<Project>{447e8ba5-30e3-4521-b6f6-51a064098026}</Project>
<Name>Migrations</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.12.0\build\NUnit.props'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.17.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.17.0\build\net35\NUnit3TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\SQLitePCLRaw.lib.e_sqlite3.2.0.2\build\net461\SQLitePCLRaw.lib.e_sqlite3.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SQLitePCLRaw.lib.e_sqlite3.2.0.2\build\net461\SQLitePCLRaw.lib.e_sqlite3.targets'))" />
<Error Condition="!Exists('..\packages\FluentMigrator.Runner.SqlServerCe.3.2.8\build\netstandard2.0\FluentMigrator.Runner.SqlServerCe.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\FluentMigrator.Runner.SqlServerCe.3.2.8\build\netstandard2.0\FluentMigrator.Runner.SqlServerCe.targets'))" />
</Target>
<Import Project="..\packages\SQLitePCLRaw.lib.e_sqlite3.2.0.2\build\net461\SQLitePCLRaw.lib.e_sqlite3.targets" Condition="Exists('..\packages\SQLitePCLRaw.lib.e_sqlite3.2.0.2\build\net461\SQLitePCLRaw.lib.e_sqlite3.targets')" />
<Import Project="..\packages\FluentMigrator.Runner.SqlServerCe.3.2.8\build\netstandard2.0\FluentMigrator.Runner.SqlServerCe.targets" Condition="Exists('..\packages\FluentMigrator.Runner.SqlServerCe.3.2.8\build\netstandard2.0\FluentMigrator.Runner.SqlServerCe.targets')" />
</Project>
\ No newline at end of file
using Coscine.Configuration;
using Coscine.Database.Helpers;
using Coscine.Migrations;
using NUnit.Framework;
using System;
namespace Migrations.Tests
{
[TestFixture]
public class MigrationsTests
{
private CoscineMigrations _migrator;
private DatabaseMasterHelper _helper;
private string _databaseName;
[OneTimeSetUp]
public void OneTimeSetUp()
{
_databaseName = $"Coscine_Migrations.Tests_{Guid.NewGuid()}";
_migrator = new CoscineMigrations();
var settings = new ConfigurationConnectionSettings() { Configuration = new ConsulConfiguration ()};
settings.LoadSettingsFromConfiguration();
_migrator.ConnectionSettings = settings;
_migrator.ConnectionSettings.Database = _databaseName;
_helper = new DatabaseMasterHelper
{
ConnectionSettings = settings
};
}
[OneTimeTearDown]
public void OneTimeTearDown()
{
if (_helper.DatabaseExists(_databaseName))
{
_helper.KillConnectionsToDatabase(_databaseName);
_helper.DropDatabase(_databaseName);
}
}
[Test]
public void MigrationTest()
{
_helper.EnsureDatabase(_databaseName);
_migrator.MigrateUp();
_helper.KillConnectionsToDatabase(_databaseName);
_helper.DropDatabase(_databaseName);
}
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by Cake.
// </auto-generated>
//------------------------------------------------------------------------------
using System.Reflection;
[assembly: AssemblyTitle("Migrations.Tests")]
[assembly: AssemblyDescription("Migrations.Tests is a part of the CoScInE group.")]
[assembly: AssemblyCompany("IT Center, RWTH Aachen University")]
[assembly: AssemblyProduct("Migrations.Tests")]
[assembly: AssemblyVersion("1.6.3")]
[assembly: AssemblyFileVersion("1.6.3")]
[assembly: AssemblyInformationalVersion("1.6.3-topic-894-automa0010")]
[assembly: AssemblyCopyright("2020 IT Center, RWTH Aachen University")]
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Consul" version="0.7.2.6" targetFramework="net461" />
<package id="Coscine.Configuration" version="1.5.0" targetFramework="net461" />
<package id="Coscine.Database.Helpers" version="1.1.0-topic-894-automa0005" targetFramework="net461" />
<package id="FluentMigrator" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Abstractions" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Extensions.Oracle" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Extensions.Postgres" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Extensions.SqlAnywhere" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Extensions.SqlServer" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Runner" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Runner.Core" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Runner.Db2" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Runner.Firebird" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Runner.Hana" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Runner.Jet" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Runner.MySql" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Runner.Oracle" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Runner.Postgres" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Runner.Redshift" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Runner.SqlAnywhere" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Runner.SQLite" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Runner.SqlServer" version="3.2.8" targetFramework="net461" />
<package id="FluentMigrator.Runner.SqlServerCe" version="3.2.8" targetFramework="net461" />
<package id="Microsoft.Data.Sqlite" version="3.1.5" targetFramework="net461" />
<package id="Microsoft.Data.Sqlite.Core" version="3.1.5" targetFramework="net461" />
<package id="Microsoft.Extensions.Configuration.Abstractions" version="2.0.1" targetFramework="net461" />
<package id="Microsoft.Extensions.DependencyInjection" version="2.0.0" targetFramework="net461" />
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.0.0" targetFramework="net461" />
<package id="Microsoft.Extensions.Logging" version="2.0.1" targetFramework="net461" />
<package id="Microsoft.Extensions.Logging.Abstractions" version="2.0.1" targetFramework="net461" />
<package id="Microsoft.Extensions.Options" version="2.0.1" targetFramework="net461" />
<package id="Microsoft.Extensions.Primitives" version="2.0.0" targetFramework="net461" />
<package id="NUnit" version="3.12.0" targetFramework="net461" />
<package id="NUnit3TestAdapter" version="3.17.0" targetFramework="net461" />
<package id="SQLitePCLRaw.bundle_e_sqlite3" version="2.0.2" targetFramework="net461" />
<package id="SQLitePCLRaw.core" version="2.0.2" targetFramework="net461" />
<package id="SQLitePCLRaw.lib.e_sqlite3" version="2.0.2" targetFramework="net461" />
<package id="SQLitePCLRaw.provider.dynamic_cdecl" version="2.0.2" targetFramework="net461" />
<package id="System.Buffers" version="4.4.0" targetFramework="net461" />
<package id="System.ComponentModel.Annotations" version="4.4.1" targetFramework="net461" />
<package id="System.Memory" version="4.5.3" targetFramework="net461" />
<package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net461" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net461" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />
</packages>
\ No newline at end of file
......@@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Migrator", "Migrator\Migrat
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Migrations", "Migrations\Migrations.csproj", "{447E8BA5-30E3-4521-B6F6-51A064098026}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Migrations.Tests", "Migrations.Tests\Migrations.Tests.csproj", "{6A8B7CA4-F59C-47EC-A6E9-D5AAA69D5BB1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -21,6 +23,10 @@ Global
{447E8BA5-30E3-4521-B6F6-51A064098026}.Debug|Any CPU.Build.0 = Debug|Any CPU
{447E8BA5-30E3-4521-B6F6-51A064098026}.Release|Any CPU.ActiveCfg = Release|Any CPU
{447E8BA5-30E3-4521-B6F6-51A064098026}.Release|Any CPU.Build.0 = Release|Any CPU
{6A8B7CA4-F59C-47EC-A6E9-D5AAA69D5BB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6A8B7CA4-F59C-47EC-A6E9-D5AAA69D5BB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A8B7CA4-F59C-47EC-A6E9-D5AAA69D5BB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A8B7CA4-F59C-47EC-A6E9-D5AAA69D5BB1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
using Coscine.Configuration;
using Coscine.Database.Helpers;
using FluentMigrator.Runner;
using Microsoft.Extensions.DependencyInjection;
using System.Data.SqlClient;
using System.Reflection;
namespace Coscine.Migrations
{
public class CoscineMigrations
{
// Format: Data Source={DBSERVER};Database={DATABASENAME};User Id={USER};Password={PASSWORD};
private const string DbDataSourceKey = "coscine/global/db_data_source";
private const string DbNameKey = "coscine/global/db_name";
private const string DbUserIdKey = "coscine/global/db_user_id";
private const string DbPasswordKey = "coscine/global/db_password";
private readonly IConfiguration _configuration;
private ServiceProvider _serviceProvider;
public string ConnectionString { get; set; }
public ConnectionSettings ConnectionSettings { get; set; }
public Assembly TargetAssembly { get; set; } = typeof(CoscineMigrations).Assembly;
public CoscineMigrations()
{
_configuration = new ConsulConfiguration();
ConnectionString = GetServerConnectionStringFromConsul();
}
public CoscineMigrations(IConfiguration configuration)
{
_configuration = configuration;
ConnectionString = GetServerConnectionStringFromConsul();
}
public void SetServiceProvider(System.Reflection.Assembly targetAssembly, string dbConnectionString)
public ServiceProvider CreateServices()
{
var serviceProvider = new ServiceCollection()
return CreateServices(TargetAssembly, ConnectionSettings.GetConnectionString());
}
public ServiceProvider CreateServices(string dbConnectionString)
{
return CreateServices(TargetAssembly, dbConnectionString);
}
public ServiceProvider CreateServices(Assembly targetAssembly, string dbConnectionString)
{
return new ServiceCollection()
// Registration of all FluentMigrator-specific services
.AddFluentMigratorCore()
// Configure the runner
......@@ -49,121 +53,48 @@ namespace Coscine.Migrations
// Enable logging to console in the FluentMigrator way
.AddLogging(lb => lb.AddFluentMigratorConsole())
.BuildServiceProvider();
_serviceProvider = serviceProvider;
}
public void CreateDatabse(string dbDatabase)
{
var sqlCommandBuilder = new SqlCommandBuilder();
using (var connection = new SqlConnection(ConnectionString))
{
connection.Open();
var command = connection.CreateCommand();
command.CommandText = $"CREATE DATABASE {sqlCommandBuilder.QuoteIdentifier(dbDatabase)};";
command.ExecuteNonQuery();
}
}
public void DropDatabase(string dbDatabase)
{
var sqlCommandBuilder = new SqlCommandBuilder();
using (var connection = new SqlConnection(ConnectionString))
{
connection.Open();
var command = connection.CreateCommand();
command.CommandText = $"DROP DATABASE {sqlCommandBuilder.QuoteIdentifier(dbDatabase)};";
command.ExecuteNonQuery();
}
}
public bool DatabaseExists(string dbDatabase)
{
var sqlCommandBuilder = new SqlCommandBuilder();
using (var connection = new SqlConnection(ConnectionString))
{
connection.Open();
var command = connection.CreateCommand();
command.CommandText = $"SELECT DB_ID('{sqlCommandBuilder.QuoteIdentifier(dbDatabase)}') AS RESULT;";
using (var reader = command.ExecuteReader())
{
if (reader.Read())
{
var result = reader["result"].ToString();
return !string.IsNullOrWhiteSpace(result);
}
}
return false;
}
}
public void EnsureDatabase(string dbDatabase)
{
if (!DatabaseExists(dbDatabase))
{
CreateDatabse(dbDatabase);
}
}
public string GetDatabaseConnectionStringFromConsul()
{
var dbDatabase = _configuration.GetString(DbNameKey);
return GetDatabaseConnectionStringFromConsul(dbDatabase);
}
public string GetDatabaseConnectionStringFromConsul(string dbDatabase)
{
var dbDataSource = _configuration.GetString(DbDataSourceKey);
var dbUserId = _configuration.GetString(DbUserIdKey);
var dbPassword = _configuration.GetString(DbPasswordKey);
return $"Data Source={dbDataSource};Database={dbDatabase};User Id={dbUserId};Password={dbPassword};";
}
public string GetServerConnectionStringFromConsul()
{
var dbDataSource = _configuration.GetString(DbDataSourceKey);
var dbUserId = _configuration.GetString(DbUserIdKey);
var dbPassword = _configuration.GetString(DbPasswordKey);
return $"Data Source={dbDataSource};User Id={dbUserId};Password={dbPassword};";
}
public string GetConsulDatabaseName()
{
return _configuration.GetString(DbNameKey);
.BuildServiceProvider(false);
}
public void MigrateUp()
{
// Put the database update into a scope to ensure
// that all resources will be disposed.
using (var scope = _serviceProvider.CreateScope())
using (var service = CreateServices())
{
// Instantiate the runner
var runner = scope.ServiceProvider.GetRequiredService<IMigrationRunner>();
using (var scope = service.CreateScope())
{
// Instantiate the runner
var runner = scope.ServiceProvider.GetRequiredService<IMigrationRunner>();
// Execute the migrations
runner.MigrateUp();
// Execute the migrations
runner.MigrateUp();
}
}
}
public void RollBack(int steps)
{
using (var scope = _serviceProvider.CreateScope())
using (var service = CreateServices())
{
var runner = scope.ServiceProvider.GetRequiredService<IMigrationRunner>();
runner.Rollback(steps);
using (var scope = CreateServices().CreateScope())
{
var runner = scope.ServiceProvider.GetRequiredService<IMigrationRunner>();
runner.Rollback(steps);
}
}
}
// Currently not in use
public void MigrateDown(FluentMigrator.IMigration targetMigration)
{
using (var scope = _serviceProvider.CreateScope())
using (var service = CreateServices())
{
var runner = scope.ServiceProvider.GetRequiredService<IMigrationRunner>();
runner.Down(targetMigration);
using (var scope = CreateServices().CreateScope())
{
var runner = scope.ServiceProvider.GetRequiredService<IMigrationRunner>();
runner.Down(targetMigration);
}
}
}
......
......@@ -40,6 +40,9 @@
<Reference Include="Coscine.Configuration, Version=1.5.0.0, Culture=neutral, PublicKeyToken=ce3d7a32d7dc1e5a, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Configuration.1.5.0\lib\net461\Coscine.Configuration.dll</HintPath>
</Reference>
<Reference Include="Coscine.Database.Helpers, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Database.Helpers.1.1.0-topic-894-automa0005\lib\net461\Coscine.Database.Helpers.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator, Version=3.2.8.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<HintPath>..\packages\FluentMigrator.3.2.8\lib\net461\FluentMigrator.dll</HintPath>
</Reference>
......@@ -158,7 +161,9 @@
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\net47\System.ValueTuple.dll</HintPath>
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
......
......@@ -9,8 +9,8 @@ using System.Reflection;
[assembly: AssemblyDescription("Migrations is a part of the CoScInE group.")]
[assembly: AssemblyCompany("IT Center, RWTH Aachen University")]
[assembly: AssemblyProduct("Migrations")]
[assembly: AssemblyVersion("1.6.1")]
[assembly: AssemblyFileVersion("1.6.1")]
[assembly: AssemblyInformationalVersion("1.6.1-beta0001")]
[assembly: AssemblyVersion("1.6.3")]
[assembly: AssemblyFileVersion("1.6.3")]
[assembly: AssemblyInformationalVersion("1.6.3-topic-894-automa0010")]
[assembly: AssemblyCopyright("2020 IT Center, RWTH Aachen University")]
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>