Skip to content

Commit 21d5532

Browse files
committed
Merge branch 'hotfix/2.1.1'
2 parents 84ecb43 + 2a26f2c commit 21d5532

30 files changed

Lines changed: 317 additions & 220 deletions

.appveyor.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
image: Visual Studio 2017
2-
version: 2.1.0-{build}
2+
version: 2.1.1-{build}
33
services:
44
- postgresql101
55
environment:
@@ -17,10 +17,11 @@ cache:
1717
clone_depth: 10
1818
install:
1919
- powershell .build\setup_appveyor.ps1
20-
# Install .NET Core 2.0
21-
- ps: Invoke-WebRequest -Uri "https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.ps1" -OutFile "install-dotnet.ps1"
22-
- ps: .\install-dotnet.ps1 -Version 2.1.300-rc1-008673
23-
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
20+
# The following can be used to install a custom version of .NET Core
21+
# - ps: Invoke-WebRequest -Uri "https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.ps1" -OutFile "install-dotnet.ps1"
22+
# - ps: .\install-dotnet.ps1 -Version 2.1.300-rc1-008673
23+
#
24+
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
2425
before_build:
2526
- appveyor-retry dotnet restore -v Minimal
2627
build_script:

.travis.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@ solution: EFCore.PG.sln
33
dist: trusty
44
sudo: false
55
mono: none
6-
dotnet: 2.1.300-rc1-008673
6+
dotnet: 2.1.300
77

88
services:
99
- postgresql
1010
addons:
1111
postgresql: "9.6"
1212

1313
env:
14-
- Test__Npgsql__DefaultConnection: '"Host=localhost;Database=postgres;Username=postgres;Password="'
14+
global:
15+
- Test__Npgsql__DefaultConnection: '"Host=localhost;Port=5433;Database=postgres;Username=travis;Password=travis"'
16+
- PGPORT: 5433
1517

1618
before_script:
19+
- psql -c "ALTER USER travis WITH PASSWORD 'travis'" # For PG 10 hack
1720
- psql -c 'CREATE EXTENSION hstore'
21+
- psql -c 'CREATE EXTENSION postgis'
1822
- dotnet restore -v Minimal
1923
script:
2024
- dotnet test test/EFCore.PG.Tests/EFCore.PG.Tests.csproj
@@ -24,3 +28,12 @@ cache:
2428
directories:
2529
- $HOME/.nuget/packages
2630

31+
# The following is necessary because of https://github.com/travis-ci/travis-ci/issues/6972
32+
addons:
33+
apt:
34+
packages:
35+
- postgresql-10
36+
- postgresql-client-10
37+
- postgresql-10-postgis-2.4
38+
- postgresql-10-postgis-2.4-scripts
39+
postgresql: 10

src/EFCore.PG.NTS/EFCore.PG.NTS.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<VersionPrefix>2.1.0</VersionPrefix>
3+
<VersionPrefix>2.1.1</VersionPrefix>
44
<TargetFrameworks>netstandard2.0</TargetFrameworks>
55
<AssemblyName>Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite</AssemblyName>
66
<RootNamespace>Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite</RootNamespace>
@@ -27,6 +27,6 @@
2727
</ItemGroup>
2828
<ItemGroup>
2929
<PackageReference Include="Npgsql.NetTopologySuite" Version="1.0.1" />
30-
<PackageReference Include="Npgsql" Version="4.0.0" />
30+
<PackageReference Include="Npgsql" Version="4.0.1" />
3131
</ItemGroup>
3232
</Project>

src/EFCore.PG.NodaTime/EFCore.PG.NodaTime.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<VersionPrefix>2.1.0</VersionPrefix>
3+
<VersionPrefix>2.1.1</VersionPrefix>
44
<TargetFrameworks>netstandard2.0</TargetFrameworks>
55
<AssemblyName>Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime</AssemblyName>
66
<RootNamespace>Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime</RootNamespace>
@@ -26,7 +26,7 @@
2626
<ProjectReference Include="..\EFCore.PG\EFCore.PG.csproj" />
2727
</ItemGroup>
2828
<ItemGroup>
29-
<PackageReference Include="Npgsql" Version="4.0.0" />
29+
<PackageReference Include="Npgsql" Version="4.0.1" />
3030
<PackageReference Include="Npgsql.NodaTime" Version="1.0.0" />
3131
</ItemGroup>
3232
</Project>

src/EFCore.PG.NodaTime/NodaTimePlugin.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure;
55
using Npgsql.EntityFrameworkCore.PostgreSQL.Query.ExpressionTranslators.Internal;
66
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal;
7+
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping;
8+
using NpgsqlTypes;
79

810
namespace Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime
911
{
@@ -24,6 +26,29 @@ public class NodaTimePlugin : NpgsqlEntityFrameworkPlugin
2426
readonly TimeTzMapping _timetz = new TimeTzMapping();
2527
readonly IntervalMapping _period = new IntervalMapping();
2628

29+
readonly NpgsqlRangeTypeMapping<LocalDateTime> _timestampLocalDateTimeRange;
30+
readonly NpgsqlRangeTypeMapping<Instant> _timestampInstantRange;
31+
readonly NpgsqlRangeTypeMapping<Instant> _timestamptzInstantRange;
32+
readonly NpgsqlRangeTypeMapping<ZonedDateTime> _timestamptzZonedDateTimeRange;
33+
readonly NpgsqlRangeTypeMapping<OffsetDateTime> _timestamptzOffsetDateTimeRange;
34+
readonly NpgsqlRangeTypeMapping<LocalDate> _dateRange;
35+
36+
public NodaTimePlugin()
37+
{
38+
_timestampLocalDateTimeRange = new NpgsqlRangeTypeMapping<LocalDateTime>(
39+
"tsrange", typeof(NpgsqlRange<LocalDateTime>), _timestampLocalDateTime, NpgsqlDbType.Range | NpgsqlDbType.Timestamp);
40+
_timestampInstantRange = new NpgsqlRangeTypeMapping<Instant>(
41+
"tsrange", typeof(NpgsqlRange<Instant>), _timestampInstant, NpgsqlDbType.Range | NpgsqlDbType.Timestamp);
42+
_timestamptzInstantRange = new NpgsqlRangeTypeMapping<Instant>(
43+
"tstzrange", typeof(NpgsqlRange<Instant>), _timestamptzInstant, NpgsqlDbType.Range | NpgsqlDbType.TimestampTz);
44+
_timestamptzZonedDateTimeRange = new NpgsqlRangeTypeMapping<ZonedDateTime>(
45+
"tstzrange", typeof(NpgsqlRange<ZonedDateTime>), _timestamptzZonedDateTime, NpgsqlDbType.Range | NpgsqlDbType.TimestampTz);
46+
_timestamptzOffsetDateTimeRange = new NpgsqlRangeTypeMapping<OffsetDateTime>(
47+
"tstzrange", typeof(NpgsqlRange<OffsetDateTime>), _timestamptzOffsetDateTime, NpgsqlDbType.Range | NpgsqlDbType.TimestampTz);
48+
_dateRange = new NpgsqlRangeTypeMapping<LocalDate>(
49+
"daterange", typeof(NpgsqlRange<LocalDate>), _date, NpgsqlDbType.Range | NpgsqlDbType.Date);;
50+
}
51+
2752
public override void AddMappings(NpgsqlTypeMappingSource typeMappingSource)
2853
{
2954
typeMappingSource.ClrTypeMappings[typeof(Instant)] = _timestampInstant;
@@ -38,7 +63,7 @@ public override void AddMappings(NpgsqlTypeMappingSource typeMappingSource)
3863

3964
typeMappingSource.StoreTypeMappings["timestamptz"] =
4065
typeMappingSource.StoreTypeMappings["timestamp with time zone"] =
41-
new RelationalTypeMapping[] { _timestamptzInstant, _timestamptzOffsetDateTime, _timestamptzZonedDateTime };
66+
new RelationalTypeMapping[] { _timestamptzInstant, _timestamptzZonedDateTime, _timestamptzOffsetDateTime };
4267

4368
typeMappingSource.ClrTypeMappings[typeof(LocalDate)] = _date;
4469
typeMappingSource.StoreTypeMappings["date"] = new RelationalTypeMapping[] { _date };
@@ -51,6 +76,22 @@ public override void AddMappings(NpgsqlTypeMappingSource typeMappingSource)
5176

5277
typeMappingSource.ClrTypeMappings[typeof(Period)] = _period;
5378
typeMappingSource.StoreTypeMappings["interval"] = new RelationalTypeMapping[] { _period };
79+
80+
// Ranges
81+
typeMappingSource.ClrTypeMappings[typeof(NpgsqlRange<Instant>)] = _timestampInstantRange;
82+
typeMappingSource.ClrTypeMappings[typeof(NpgsqlRange<LocalDateTime>)] = _timestampLocalDateTimeRange;
83+
84+
typeMappingSource.StoreTypeMappings["tsrange"] =
85+
new RelationalTypeMapping[] { _timestampInstantRange, _timestampLocalDateTimeRange };
86+
87+
typeMappingSource.ClrTypeMappings[typeof(NpgsqlRange<ZonedDateTime>)] = _timestamptzZonedDateTimeRange;
88+
typeMappingSource.ClrTypeMappings[typeof(NpgsqlRange<OffsetDateTime>)] = _timestamptzOffsetDateTimeRange;
89+
90+
typeMappingSource.StoreTypeMappings["tstzrange"] =
91+
new RelationalTypeMapping[] { _timestamptzInstantRange, _timestamptzZonedDateTimeRange, _timestamptzOffsetDateTimeRange };
92+
93+
typeMappingSource.ClrTypeMappings[typeof(NpgsqlRange<LocalDate>)] = _dateRange;
94+
typeMappingSource.StoreTypeMappings["daterange"] = new RelationalTypeMapping[] { _dateRange };
5495
}
5596

5697
static readonly IMemberTranslator[] MemberTranslators =

src/EFCore.PG/EFCore.PG.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<VersionPrefix>2.1.0</VersionPrefix>
3+
<VersionPrefix>2.1.1</VersionPrefix>
44
<TargetFrameworks>netstandard2.0</TargetFrameworks>
55
<AssemblyName>Npgsql.EntityFrameworkCore.PostgreSQL</AssemblyName>
66
<RootNamespace>Npgsql.EntityFrameworkCore.PostgreSQL</RootNamespace>
@@ -22,10 +22,10 @@
2222
<ItemGroup>
2323
<!-- PrivateAssets="none" is set to flow the EF Core analyzer to users referencing this package
2424
https://github.com/aspnet/EntityFrameworkCore/pull/11350 -->
25-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.0" PrivateAssets="none" />
26-
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.1.0" PrivateAssets="none" />
27-
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="2.1.0" PrivateAssets="none" />
28-
<PackageReference Include="Npgsql" Version="4.0.0" />
25+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.1" PrivateAssets="none" />
26+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.1.1" PrivateAssets="none" />
27+
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="2.1.1" PrivateAssets="none" />
28+
<PackageReference Include="Npgsql" Version="4.0.1" />
2929
</ItemGroup>
3030
<ItemGroup>
3131
<None Update="Properties\NpgsqlStrings.Designer.tt">

src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Migrations
4242
public class NpgsqlMigrationsSqlGenerator : MigrationsSqlGenerator
4343
{
4444
readonly NpgsqlSqlGenerationHelper _sqlGenerationHelper;
45+
readonly NpgsqlTypeMappingSource _typeMappingSource;
4546

4647
public NpgsqlMigrationsSqlGenerator([NotNull] MigrationsSqlGeneratorDependencies dependencies)
4748
: base(dependencies)
4849
{
4950
_sqlGenerationHelper = (NpgsqlSqlGenerationHelper)dependencies.SqlGenerationHelper;
51+
_typeMappingSource = (NpgsqlTypeMappingSource)dependencies.TypeMappingSource;
5052
}
5153

5254
protected override void Generate(MigrationOperation operation, [CanBeNull] IModel model, MigrationCommandListBuilder builder)
@@ -430,7 +432,8 @@ protected override void Generate(AlterColumnOperation operation, IModel model, M
430432
.Append(" OWNED BY ")
431433
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Table))
432434
.Append('.')
433-
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name));
435+
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name))
436+
.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);
434437
}
435438

436439
// Comment
@@ -447,7 +450,8 @@ protected override void Generate(AlterColumnOperation operation, IModel model, M
447450
.Append('.')
448451
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name))
449452
.Append(" IS ")
450-
.Append(stringTypeMapping.GenerateSqlLiteral(newComment));
453+
.Append(stringTypeMapping.GenerateSqlLiteral(newComment))
454+
.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);
451455
}
452456

453457
EndStatement(builder);
@@ -800,6 +804,11 @@ protected override void ColumnDefinition(
800804
if (type == null)
801805
type = GetColumnType(schema, table, name, clrType, unicode, maxLength, rowVersion, model);
802806

807+
// User-defined type names are quoted if they contain uppercase letters. Other types are never quoted
808+
// since users sometimes prefer to write TEXT instead of text.
809+
if (_typeMappingSource.IsUserDefinedType(type))
810+
type = _sqlGenerationHelper.DelimitIdentifier(type);
811+
803812
CheckForOldValueGenerationAnnotation(annotatable);
804813
var valueGenerationStrategy = annotatable[NpgsqlAnnotationNames.ValueGenerationStrategy] as NpgsqlValueGenerationStrategy?;
805814
if (valueGenerationStrategy == NpgsqlValueGenerationStrategy.SerialColumn)

src/EFCore.PG/Query/Expressions/Internal/ILikeExpression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ public override bool Equals(object obj)
161161
return true;
162162
}
163163

164-
return obj.GetType() == GetType() && Equals((LikeExpression)obj);
164+
return obj.GetType() == GetType() && Equals((ILikeExpression)obj);
165165
}
166166

167-
private bool Equals(LikeExpression other)
167+
bool Equals(ILikeExpression other)
168168
=> Equals(Match, other.Match)
169169
&& Equals(Pattern, other.Pattern)
170170
&& Equals(EscapeChar, other.EscapeChar);

src/EFCore.PG/Scaffolding/Internal/NpgsqlDatabaseModelFactory.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public virtual DatabaseModel Create(DbConnection dbConnection, IEnumerable<strin
144144
continue;
145145
}
146146

147-
// We may have dropped columns. We load these because constraints take them into
147+
// We may have dropped or skipped columns. We load these because constraints take them into
148148
// account when referencing columns, but must now get rid of them before returning
149149
// the database model.
150150
while (table.Columns.Remove(null)) {}
@@ -318,6 +318,9 @@ nspname NOT IN ('pg_catalog', 'information_schema') AND
318318
if (_enums.Contains(formattedTypeName) || _enums.Contains(formattedBaseTypeName))
319319
{
320320
_logger.EnumColumnSkippedWarning(DisplayName(tableSchema, tableName) + '.' + column.Name);
321+
// We need to know about skipped columns because constraints take them into
322+
// account when referencing columns. We'll get rid of them before returning the model.
323+
table.Columns.Add(null);
321324
continue;
322325
}
323326

@@ -701,6 +704,13 @@ FROM information_schema.sequences
701704
var ownerDatabaseTable = tables
702705
.FirstOrDefault(t => t.Name == ownerTable && t.Schema == ownerSchema);
703706

707+
if (ownerDatabaseTable == null)
708+
{
709+
// The sequence is owned by a table that isn't being scaffolded because it was excluded
710+
// from the table selection set. Skip the sequence.
711+
continue;
712+
}
713+
704714
var ownerDatabaseColumn = ownerDatabaseTable
705715
.Columns
706716
.FirstOrDefault(t => t.Name == ownerColumn);

src/EFCore.PG/Storage/Internal/Mapping/NpgsqlArrayTypeMapping.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ protected override string GenerateNonNullSqlLiteral(object value)
8686
sb.Append(",");
8787
}
8888

89-
sb.Append("]");
89+
sb.Append("]::");
90+
sb.Append(ElementMapping.StoreType);
91+
sb.Append("[]");
9092
return sb.ToString();
9193
}
9294

0 commit comments

Comments
 (0)