Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
koistya committed Dec 15, 2011
0 parents commit 3db9c70
Show file tree
Hide file tree
Showing 35 changed files with 15,667 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .gitignore
@@ -0,0 +1,37 @@
Thumbs.db
*.obj
*.exe
*.pdb
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
*.vsdoc
*.dbmdl
*.dbmdl.schemaview
*.dbmdl.user
[Bb]in
[Dd]ebug*/
*.lib
*.sbr
obj/
[Rr]elease*/
_ReSharper*/
[Tt]est[Rr]esult*
*.gpState
StyleCop.Cache
*.Full.*
References/
*.testsettings
*.vsmdi
*.Tests/
27 changes: 27 additions & 0 deletions Data.sln
@@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FF29A2C7-8703-44F8-B4C6-F3F1297BD333}"
ProjectSection(SolutionItems) = preProject
LICENSE.md = LICENSE.md
README.md = README.md
Solution Items\SolutionInfo.cs = Solution Items\SolutionInfo.cs
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFramework.SchemaCompare", "EntityFramework.SchemaCompare\EntityFramework.SchemaCompare.csproj", "{13735015-B841-4BFF-9D16-DEC0C0556320}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{13735015-B841-4BFF-9D16-DEC0C0556320}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{13735015-B841-4BFF-9D16-DEC0C0556320}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13735015-B841-4BFF-9D16-DEC0C0556320}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13735015-B841-4BFF-9D16-DEC0C0556320}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
87 changes: 87 additions & 0 deletions EntityFramework.SchemaCompare/CheckCompatibilityWithModel.cs
@@ -0,0 +1,87 @@
//-------------------------------------------------------------------------------
// <copyright file="CheckCompatibilityWithModel.cs" company="KriaSoft, LLC">
// Copyright (c) 2011 Konstantin Tarkus, KriaSoft LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
//-------------------------------------------------------------------------------

namespace System.Data.Entity
{
using System.Data.Entity.SchemaCompare.Infrastructure;
using System.Linq;
using System.Transactions;

/// <summary>
/// An implementation of <see cref="T:IDatabaseInitializer"/> that will compare
/// database schema with the entity model and throw an exception if critical
/// conflicts are found.
/// </summary>
/// <typeparam name="TContext">The type of the context.</typeparam>
public class CheckCompatibilityWithModel<TContext> : IDatabaseInitializer<TContext> where TContext : DbContext
{
/// <summary>
/// Initializes a new instance of the <see cref="T:System.Data.Entity.CheckCompatibilityWithModel`1"/> class.
/// </summary>
public CheckCompatibilityWithModel()
{
this.CreateDatabaseIfNotExists = true;
}

/// <summary>
/// Gets or sets a value indicating whether the database should be re-created
/// and optionally re-seeded if it does not exist. To seed the database,
/// create a derived class and override the Seed method. Default is True.
/// </summary>
public bool CreateDatabaseIfNotExists { get; set; }

/// <summary>
/// Executes the strategy to initialize the database for the given context.
/// </summary>
/// <param name="context">The context.</param>
public void InitializeDatabase(TContext context)
{
bool exists;

using (new TransactionScope(TransactionScopeOption.Suppress))
{
exists = context.Database.Exists();
}

if (exists)
{
var compatibilityIssues = context.Database.FindCompatibilityIssues();

if (compatibilityIssues.Any(x => x.IsCritical))
{
throw new DatabaseComparisonException(context, compatibilityIssues);
}
}
else if (this.CreateDatabaseIfNotExists)
{
context.Database.Create();
this.Seed(context);
context.SaveChanges();
}
}

/// <summary>
/// A that should be overridden to actually add data to the context for
/// seeding. The default implementation does nothing.
/// </summary>
/// <param name="context">The context to seed.</param>
protected virtual void Seed(TContext context)
{
}
}
}
61 changes: 61 additions & 0 deletions EntityFramework.SchemaCompare/ClassDiagram.cd
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1">
<Class Name="System.Data.Entity.DatabaseExtensions">
<Position X="3.75" Y="0.5" Width="2.25" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>DatabaseExtensions.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="System.Data.Entity.CheckCompatibilityWithModel&lt;TContext&gt;">
<Position X="0.5" Y="0.5" Width="3" />
<TypeIdentifier>
<HashCode>AAAgAAAAAAAAAAAAAEAAAAAEAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>CheckCompatibilityWithModel.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Class Name="System.Data.Entity.SchemaCompare.Infrastructure.DatabaseComparisonException">
<Position X="8.25" Y="0.5" Width="2.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Infrastructure\DatabaseComparisonException.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="System.Data.Entity.SchemaCompare.Infrastructure.CompatibilityIssue">
<Position X="6.25" Y="0.5" Width="1.75" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAA=</HashCode>
<FileName>Infrastructure\CompatibilityIssue.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="System.Data.Entity.SchemaCompare.Model.Column">
<Position X="4" Y="3" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Model\Column.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="System.Data.Entity.SchemaCompare.Model.DatabaseContext">
<Position X="0.5" Y="3" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAABAAAAAAAAAAAAAQAAAEAAAAAAAAAAAAAgAAAA=</HashCode>
<FileName>Model\DatabaseContext.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="System.Data.Entity.SchemaCompare.Model.Table">
<Position X="2.25" Y="3" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAgAAAAAAAAAQEAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Model\Table.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="System.Data.Entity.SchemaCompare.Sql.SqlQuery">
<Position X="8.25" Y="2.5" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAICAAAAAAAAAEAAAAAAAggAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Sql\SqlQuery.cs</FileName>
</TypeIdentifier>
</Class>
<Font Name="Segoe UI" Size="9" />
</ClassDiagram>
63 changes: 63 additions & 0 deletions EntityFramework.SchemaCompare/DatabaseExtensions.cs
@@ -0,0 +1,63 @@
//-------------------------------------------------------------------------------
// <copyright file="DatabaseExtensions.cs" company="KriaSoft, LLC">
// Copyright (c) 2011 Konstantin Tarkus, KriaSoft LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
//-------------------------------------------------------------------------------

namespace System.Data.Entity
{
using System.Collections.Generic;
using System.Data.Entity.SchemaCompare.Infrastructure;
using System.Data.Entity.SchemaCompare.Model;
using System.Data.Entity.SchemaCompare.Sql;
using System.Linq;

/// <summary>
/// Extension methods for <see cref="T:Database"/> class.
/// </summary>
public static class DatabaseExtensions
{
/// <summary>
/// Compares database with the model and returns a list of <see cref="T:CompatibilityIssue"/>.
/// </summary>
/// <param name="database">Database context.</param>
/// <returns>A list of compatibility issues.</returns>
public static IList<CompatibilityIssue> FindCompatibilityIssues(this Database database)
{
//// Reads database schema

List<Table> tables;

using (var db = new DatabaseContext(database.Connection))
{
db.ObjectContext.Connection.Open();

using (var cmd = db.Database.Connection.CreateCommand())
{
cmd.CommandText = new SqlQuery(db.Database.Connection.ServerVersion);

using (var reader = cmd.ExecuteReader())
{
tables = db.ObjectContext.Translate<Table>(reader).ToList();
}
}
}

//// TODO: Compare database schema with the model and return a list of compatibility issues.

return new List<CompatibilityIssue>();
}
}
}
94 changes: 94 additions & 0 deletions EntityFramework.SchemaCompare/EntityFramework.SchemaCompare.csproj
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{13735015-B841-4BFF-9D16-DEC0C0556320}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>System.Data.Entity.SchemaCompare</RootNamespace>
<AssemblyName>EntityFramework.SchemaCompare</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>
<ItemGroup>
<Reference Include="EntityFramework, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\EntityFramework.4.2.0.0\lib\net40\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Data.Entity" />
<Reference Include="System.Transactions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Solution Items\SolutionInfo.cs">
<Link>Properties\SolutionInfo.cs</Link>
</Compile>
<Compile Include="CheckCompatibilityWithModel.cs" />
<Compile Include="Infrastructure\CompatibilityIssue.cs" />
<Compile Include="DatabaseExtensions.cs" />
<Compile Include="Infrastructure\DatabaseComparisonException.cs" />
<Compile Include="Model\Column.cs" />
<Compile Include="Model\DatabaseContext.cs" />
<Compile Include="Model\Table.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\Errors.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Errors.resx</DependentUpon>
</Compile>
<Compile Include="Sql\SqlQuery.cs" />
</ItemGroup>
<ItemGroup>
<None Include="ClassDiagram.cd" />
<None Include="Packages.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Errors.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Errors.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Sql\SelectTables_8.00.sql">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Sql\SelectTables_9.00+.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>

0 comments on commit 3db9c70

Please sign in to comment.