Skip to content

Commit

Permalink
Merge branch 'hotfix/1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Jul 21, 2016
2 parents aca36a2 + a6409ee commit 12cada0
Show file tree
Hide file tree
Showing 16 changed files with 243 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Migrations.Operations;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Migrations.Design
{
public class NpgsqlCSharpMigrationOperationGenerator : CSharpMigrationOperationGenerator
{
readonly CSharpHelper _code;

public NpgsqlCSharpMigrationOperationGenerator(
[NotNull] CSharpHelper codeHelper,
[NotNull] IDatabaseProviderServices providerServices
) : base(codeHelper)
{
_code = codeHelper;
}

protected override void Generate([NotNull] MigrationOperation operation, [NotNull] IndentedStringBuilder builder)
{
Check.NotNull(operation, nameof(operation));
Check.NotNull(builder, nameof(builder));

var asCreateExtensionOperation = operation as NpgsqlCreatePostgresExtensionOperation;
if (asCreateExtensionOperation != null)
{
Generate(asCreateExtensionOperation, builder);
return;
}

var asDropExtensionOperation = operation as NpgsqlDropPostgresExtensionOperation;
if (asDropExtensionOperation != null)
{
Generate(asDropExtensionOperation, builder);
return;
}

throw new InvalidOperationException(DesignCoreStrings.UnknownOperation(operation.GetType()));
}

protected virtual void Generate([NotNull] NpgsqlCreatePostgresExtensionOperation operation, [NotNull] IndentedStringBuilder builder)
{
Check.NotNull(operation, nameof(operation));
Check.NotNull(builder, nameof(builder));

builder.Append(".CreatePostgresExtension(");

if (operation.Schema == null && operation.Version == null)
{
builder.Append(_code.Literal(operation.Name));
}
else
{
using (builder.Indent())
{
builder
.Append("name: ")
.Append(_code.Literal(operation.Name));

if (operation.Schema != null)
{
builder
.AppendLine(",")
.Append("schema: ")
.Append(_code.Literal(operation.Schema));
}

if (operation.Version != null)
{
builder
.AppendLine(",")
.Append("version: ")
.Append(_code.Literal(operation.Version));
}
}
}
builder.Append(")");

Annotations(operation.GetAnnotations(), builder);
}

protected virtual void Generate([NotNull] NpgsqlDropPostgresExtensionOperation operation, [NotNull] IndentedStringBuilder builder)
{
Check.NotNull(operation, nameof(operation));
Check.NotNull(builder, nameof(builder));

builder
.Append(".DropPostgresExtension(")
.Append(_code.Literal(operation.Name))
.Append(")");

Annotations(operation.GetAnnotations(), builder);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<Compile Include="Metadata\NpgsqlIndexModelAnnotations.cs" />
<Compile Include="Metadata\NpgsqlColumnModelAnnotations.cs" />
<Compile Include="Metadata\NpgsqlDatabaseModelAnnotationNames.cs" />
<Compile Include="Migrations\Design\NpgsqlCSharpMigrationOperationGenerator.cs" />
<Compile Include="NpgsqlDatabaseModelFactory.cs" />
<Compile Include="NpgsqlDesignTimeServices.cs" />
<Compile Include="NpgsqlScaffoldingModelFactory.cs" />
Expand Down Expand Up @@ -81,4 +82,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"dependencies" : {
"Microsoft.EntityFrameworkCore": "1.0.0",
"Microsoft.EntityFrameworkCore.Design.Core": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Relational": "1.0.0",
"Microsoft.EntityFrameworkCore.Relational.Design": "1.0.0",
"Microsoft.Extensions.DependencyInjection": "1.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.25420" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.25420</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>180fc3ca-e92e-4b89-8a3a-81302f088f2e</ProjectGuid>
<RootNamespace>Npgsql.EntityFrameworkCore.PostgreSQL.Design</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations.Design;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -36,6 +37,7 @@ public virtual IServiceCollection ConfigureDesignTimeServices([NotNull] IService
.AddSingleton<IScaffoldingModelFactory, NpgsqlScaffoldingModelFactory>()
.AddSingleton<IRelationalAnnotationProvider, NpgsqlAnnotationProvider>()
.AddSingleton<IRelationalTypeMapper, NpgsqlTypeMapper>()
.AddSingleton<CSharpMigrationOperationGenerator, NpgsqlCSharpMigrationOperationGenerator>()
.AddSingleton<IDatabaseModelFactory, NpgsqlDatabaseModelFactory>();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.0",
"version": "1.0.1",
"packOptions": {
"authors": [ "Shay Rojansky" ],
"description": "Design-time Entity Framework Core Functionality for PostgreSQL",
Expand All @@ -19,6 +19,7 @@
},
"dependencies" : {
"Microsoft.EntityFrameworkCore": "1.0.0",
"Microsoft.EntityFrameworkCore.Design.Core": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Relational": "1.0.0",
"Microsoft.EntityFrameworkCore.Relational.Design": "1.0.0",
"Microsoft.Extensions.DependencyInjection": "1.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Migrations.Operations;
using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Migrations
{
public static class MigrationBuilderExtensions
{
static readonly string NpgsqlProviderName = typeof(MigrationBuilderExtensions).GetTypeInfo().Assembly.GetName().Name;

public static OperationBuilder<NpgsqlCreatePostgresExtensionOperation> CreatePostgresExtension(
this MigrationBuilder builder,
[NotNull] string name,
string schema = null,
string version = null
)
{
Check.NotEmpty(name, nameof(name));
Check.NullButNotEmpty(schema, nameof(schema));
Check.NullButNotEmpty(version, nameof(schema));

var operation = new NpgsqlCreatePostgresExtensionOperation
{
Name = name,
Schema = schema,
Version = version
};

if (builder.ActiveProvider == NpgsqlProviderName)
builder.Operations.Add(operation);

return new OperationBuilder<NpgsqlCreatePostgresExtensionOperation>(operation);
}

public static OperationBuilder<NpgsqlDropPostgresExtensionOperation> DropPostgresExtension(
this MigrationBuilder builder,
[NotNull] string name
)
{
Check.NotEmpty(name, nameof(name));

var operation = new NpgsqlDropPostgresExtensionOperation { Name = name };

if (builder.ActiveProvider == NpgsqlProviderName)
builder.Operations.Add(operation);

return new OperationBuilder<NpgsqlDropPostgresExtensionOperation>(operation);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ public virtual void Generate(NpgsqlCreatePostgresExtensionOperation operation, [
Check.NotNull(builder, nameof(builder));

builder
.Append("CREATE EXTENSION ")
.Append("CREATE EXTENSION IF NOT EXISTS ")
.Append(SqlGenerationHelper.DelimitIdentifier(operation.Name));

if (operation.Schema != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<Compile Include="Metadata\NpgsqlModelAnnotations.cs" />
<Compile Include="Metadata\PostgresExtension.cs" />
<Compile Include="Migrations\Internal\NpgsqlMigrationsModelDiffer.cs" />
<Compile Include="Migrations\MigrationBuilderExtensions.cs" />
<Compile Include="Migrations\Operations\NpgsqlCreatePostgresExtensionOperation.cs" />
<Compile Include="Migrations\Operations\NpgsqlCreateDatabaseOperation.cs" />
<Compile Include="Migrations\Operations\NpgsqlDropDatabaseOperation.cs" />
Expand Down Expand Up @@ -135,4 +136,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.25420" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.25420</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>a6370fdf-2140-4780-9671-ffce9688a1ab</ProjectGuid>
<RootNamespace>Npgsql.EntityFrameworkCore.PostgreSQL</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,32 @@ namespace Microsoft.EntityFrameworkCore.Query.ExpressionTranslators.Internal
{
public class NpgsqlStringSubstringTranslator : IMethodCallTranslator
{
private static readonly MethodInfo _methodInfo = typeof(string).GetTypeInfo().GetDeclaredMethods(nameof(string.Substring))
.Where(m => m.GetParameters().Count() == 2)
.Single();
private static readonly MethodInfo _methodInfo = typeof(string).GetTypeInfo()
.GetDeclaredMethods(nameof(string.Substring))
.Single(m => m.GetParameters().Length == 2);

public virtual Expression Translate([NotNull] MethodCallExpression methodCallExpression)
{
if (methodCallExpression.Method == _methodInfo)
{
var sqlArguments = new[] { methodCallExpression.Object }.Concat(methodCallExpression.Arguments);
return new SqlFunctionExpression("SUBSTRING", methodCallExpression.Type, sqlArguments);
}

return null;
}
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
[CanBeNull]
public virtual Expression Translate(MethodCallExpression methodCallExpression)
=> methodCallExpression.Method == _methodInfo
? new SqlFunctionExpression(
"SUBSTRING",
methodCallExpression.Type,
new[]
{
methodCallExpression.Object,
// Accommodate for SQL Server assumption of 1-based string indexes
methodCallExpression.Arguments[0].NodeType == ExpressionType.Constant
? (Expression)Expression.Constant(
(int)((ConstantExpression)methodCallExpression.Arguments[0]).Value + 1)
: Expression.Add(
methodCallExpression.Arguments[0],
Expression.Constant(1)),
methodCallExpression.Arguments[1]
})
: null;
}
}
2 changes: 1 addition & 1 deletion src/Npgsql.EntityFrameworkCore.PostgreSQL/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.0",
"version": "1.0.1",
"packOptions": {
"authors": [ "Shay Rojansky" ],
"description" : "PostgreSQL provider for Entity Framework Core",
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static string NotEmpty(string value, [InvokerParameterName] [NotNull] str
return value;
}

public static string NullButNotEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
public static string NullButNotEmpty([CanBeNull] string value, [InvokerParameterName] [NotNull] string parameterName)
{
if (!ReferenceEquals(value, null)
&& (value.Length == 0))
Expand Down
6 changes: 3 additions & 3 deletions src/Shared/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
[assembly: AssemblyCopyright("Copyright © 2002 - 2016 Npgsql Development Team")]

// The following version attributes get rewritten by GitVersion as part of the build
[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyVersion("1.0.1")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: AssemblyInformationalVersion("1.0.1")]
2 changes: 1 addition & 1 deletion teamcity_set_version.cmd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
echo ##teamcity[buildNumber '1.0.0-%1']
echo ##teamcity[buildNumber '1.0.1-%1']
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,11 @@ public virtual void Can_query_using_any_mapped_data_type()
// NpgsqlPoint? param19 = new NpgsqlPoint(5.2, 3.3);
// Assert.Same(entity, context.Set<MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Point == param19));

// The following fails because of https:/aspnet/EntityFramework/issues/3617,
// or rather https:/aspnet/EntityFramework/issues/4608
//var param20 = @"{""a"": ""b""}";
//Assert.Same(entity, context.Set<MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Jsonb == param20));

// The following fails because of https:/aspnet/EntityFramework/issues/5365
// var param21 = new Dictionary<string, string> { { "a", "b" } };
// Assert.Same(entity, context.Set<MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Hstore == param21));
var param20 = @"{""a"": ""b""}";
Assert.Same(entity, context.Set<MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Jsonb == param20));

var param21 = new Dictionary<string, string> { { "a", "b" } };
Assert.Same(entity, context.Set<MappedNullableDataTypes>().Single(e => e.Int == 999 && e.Hstore == param21));

//SomeComposite param22 = new SomeComposite { SomeNumber = 8, SomeText = "foo" };
//Assert.Same(entity, context.Set<MappedNullableDataTypes>().Single(e => e.Int == 999 && e.SomeComposite.Equals(param20)));
Expand Down

0 comments on commit 12cada0

Please sign in to comment.