Skip to content

Commit

Permalink
Merge branch 'hotfix/2.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Apr 22, 2018
2 parents 5b83332 + 3b6fbd9 commit f651b8a
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
image: Visual Studio 2017 Preview
version: 2.0.1-{build}
version: 2.0.2-{build}
services:
- postgresql
environment:
Expand Down Expand Up @@ -30,7 +30,7 @@ artifacts:
- path: 'src\EFCore.PG\bin\**\*.nupkg'
deploy:
- provider: NuGet
server: https://www.myget.org/F/npgsql-unstable/api/v2/package
server: https://www.myget.org/F/npgsql/api/v2/package
api_key:
secure: kiMn9uBvgMa5EtEmTIhNBFUfyatiATnhkgx5Xj/1EsmKTtEkUv+hJAQs0L3VGzPw
artifact: /.*\.nupkg/
Expand Down
8 changes: 4 additions & 4 deletions src/EFCore.PG/EFCore.PG.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>2.0.1</VersionPrefix>
<VersionPrefix>2.0.2</VersionPrefix>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<AssemblyName>Npgsql.EntityFrameworkCore.PostgreSQL</AssemblyName>
<RootNamespace>Microsoft.EntityFrameworkCore</RootNamespace>
Expand All @@ -25,11 +25,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.0.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
<PackageReference Include="Npgsql" Version="3.2.5" />
<PackageReference Include="Npgsql" Version="3.2.7" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/EFCore.PG/Metadata/INpgsqlEntityTypeAnnotations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public interface INpgsqlEntityTypeAnnotations : IRelationalEntityTypeAnnotations
bool SetStorageParameter(string parameterName, object parameterValue);
Dictionary<string, object> GetStorageParameters();
string Comment { get; }
CockroachDbInterleaveInParent CockroachDbInterleaveInParent { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public override IEnumerable<IAnnotation> For(IEntityType entityType)
{
if (entityType.Npgsql().Comment != null)
yield return new Annotation(NpgsqlAnnotationNames.Comment, entityType.Npgsql().Comment);
if (entityType[CockroachDbAnnotationNames.InterleaveInParent] != null)
yield return new Annotation(CockroachDbAnnotationNames.InterleaveInParent, entityType[CockroachDbAnnotationNames.InterleaveInParent]);
foreach (var storageParamAnnotation in entityType.GetAnnotations()
.Where(a => a.Name.StartsWith(NpgsqlAnnotationNames.StorageParameterPrefix)))
{
Expand Down
10 changes: 8 additions & 2 deletions src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ protected override void Generate(
base.Generate(operation, model, builder, false);

// CockroachDB "interleave in parent" (https://www.cockroachlabs.com/docs/stable/interleave-in-parent.html)
var interleaveInParentStr = operation[CockroachDbAnnotationNames.InterleaveInParent] as string;
if (interleaveInParentStr != null)
if (operation[CockroachDbAnnotationNames.InterleaveInParent] is string)
{
var interleaveInParent = new CockroachDbInterleaveInParent(operation);
var parentTableSchema = interleaveInParent.ParentTableSchema;
Expand Down Expand Up @@ -518,6 +517,13 @@ protected override void Generate(
.Append(ColumnList(operation.Columns))
.Append(")");

if (!string.IsNullOrEmpty(operation.Filter))
{
builder
.Append(" WHERE ")
.Append(operation.Filter);
}

builder.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);

EndStatement(builder);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Data;
using JetBrains.Annotations;

namespace Microsoft.EntityFrameworkCore.Storage.Internal
{
public class NpgsqlTimeSpanTypeMapping : NpgsqlTypeMapping
{
public NpgsqlTimeSpanTypeMapping()
: base("interval", typeof(TimeSpan), NpgsqlTypes.NpgsqlDbType.Interval)
{
}

public override RelationalTypeMapping Clone(string storeType, int? size)
=> new NpgsqlTimeSpanTypeMapping();

protected override string GenerateNonNullSqlLiteral(object value)
{
var ts = (TimeSpan)value;
return $"INTERVAL '{ts.ToString($@"{(ts < TimeSpan.Zero ? "\\-" : "")}{(ts.Days == 0 ? "" : "d\\ ")}hh\:mm\:ss{(ts.Milliseconds == 0 ? "" : $"\\.FFF")}")}'";
}
}
}
12 changes: 9 additions & 3 deletions src/EFCore.PG/Storage/Internal/NpgsqlDatabaseCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,15 @@ public override void CreateTables()

if (reloadTypes)
{
var npgsqlConn = (NpgsqlConnection)_connection.DbConnection;
if (npgsqlConn.FullState == ConnectionState.Open)
npgsqlConn.ReloadTypes();
_connection.Open();
try
{
((NpgsqlConnection)_connection.DbConnection).ReloadTypes();
}
catch
{
_connection.Close();
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/EFCore.PG/Storage/Internal/NpgsqlEFTypeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ void AddCustomizedMappings()
// Mappings where we need literal string generation
_baseClrMappings[typeof(string)] = _storeTypeMappings["text"] = new NpgsqlStringTypeMapping("text", NpgsqlDbType.Text);
_storeTypeMappings["varchar"] = new NpgsqlStringTypeMapping("varchar", NpgsqlDbType.Varchar);
_storeTypeMappings["char"] = new NpgsqlStringTypeMapping("char", NpgsqlDbType.Char);
_storeTypeMappings["citext"] = new NpgsqlStringTypeMapping("citext", NpgsqlDbType.Citext);
_storeTypeMappings["json"] = new NpgsqlStringTypeMapping("json", NpgsqlDbType.Json);
_storeTypeMappings["jsonb"] = new NpgsqlStringTypeMapping("jsonb", NpgsqlDbType.Jsonb);

_baseClrMappings[typeof(char)] = new CharTypeMapping("text", DbType.String);
_baseClrMappings[typeof(DateTime)] = _storeTypeMappings["timestamp"] = new DateTimeTypeMapping("timestamp", DbType.DateTime);
_baseClrMappings[typeof(DateTimeOffset)] = _storeTypeMappings["timestamptz"] = new NpgsqlDateTimeOffsetTypeMapping("timestamptz", DbType.DateTimeOffset);
_baseClrMappings[typeof(TimeSpan)] = _storeTypeMappings["interval"] = new NpgsqlTimeSpanTypeMapping();
_baseClrMappings[typeof(bool)] = _storeTypeMappings["bool"] = new NpgsqlBoolTypeMapping();

_baseClrMappings[typeof(decimal)] = new DecimalTypeMapping("numeric", DbType.Decimal);
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.PG/Storage/NpgsqlStringRelationalTypeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Storage
public class NpgsqlStringRelationalTypeMapper : IStringRelationalTypeMapper
{
static readonly RelationalTypeMapping UnboundedStringMapping
= new NpgsqlTypeMapping("text", typeof(string), NpgsqlDbType.Text);
= new NpgsqlStringTypeMapping("text", NpgsqlDbType.Text);

readonly ConcurrentDictionary<int, RelationalTypeMapping> _boundedStringMappings
= new ConcurrentDictionary<int, RelationalTypeMapping>();
Expand All @@ -40,7 +40,7 @@ public RelationalTypeMapping FindMapping(bool unicode, bool keyOrIndex, int? max
{
return maxLength.HasValue
? _boundedStringMappings.GetOrAdd(maxLength.Value,
ml => new NpgsqlTypeMapping($"varchar({maxLength})", typeof(string))
ml => new NpgsqlStringTypeMapping($"varchar({maxLength})", NpgsqlDbType.Varchar)
)
: UnboundedStringMapping;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Design.Specification.Tests" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Design.Specification.Tests" Version="2.0.2" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace E2ETest.Namespace
public decimal DecimalColumn { get; set; }
public decimal NumericColumn { get; set; }
public decimal MoneyColumn { get; set; }
public char? CharColumn { get; set; }
public string CharColumn { get; set; }
public string TextColumn { get; set; }
public string VarcharColumn { get; set; }
public DateTime DateColumn { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace E2ETest.Namespace
[Column("moneyColumn", TypeName = "money")]
public decimal MoneyColumn { get; set; }
[Column("charColumn", TypeName = "char(1)")]
public char? CharColumn { get; set; }
public string CharColumn { get; set; }
[Column("textColumn")]
public string TextColumn { get; set; }
[Column("varcharColumn", TypeName = "varchar")]
Expand Down
10 changes: 5 additions & 5 deletions test/EFCore.PG.FunctionalTests/EFCore.PG.FunctionalTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta2-build1317" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Specification.Tests" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Specification.Tests" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Specification.Tests" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Specification.Tests" Version="2.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
<PackageReference Include="Npgsql" Version="3.2.5" />
<PackageReference Include="Npgsql" Version="3.2.7" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ public void AlterColumn_remove_comment()
[Fact]
public void CreateTableOperation_with_cockroach_interleave_in_parent()
{
var op =
var op =
new CreateTableOperation
{
Name = "People",
Expand Down
10 changes: 5 additions & 5 deletions test/EFCore.PG.Tests/EFCore.PG.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Specification.Tests" Version="2.0.1" />
<PackageReference Include="Npgsql" Version="3.2.5" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Specification.Tests" Version="2.0.2" />
<PackageReference Include="Npgsql" Version="3.2.7" />
</ItemGroup>

</Project>

0 comments on commit f651b8a

Please sign in to comment.