Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP on improving compatibility of efcore.pg with CockroachDB #2892

Draft
wants to merge 77 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
cec4f45
Add CI workflow for building Cockroach
giangpham712 Jun 20, 2023
5c4fbad
Update to use version 8.0.0-preview-5-ci of Npgsql packages
giangpham712 Aug 1, 2023
949315a
Run tests with blame-hang-timeout
giangpham712 Aug 1, 2023
f1c478c
Run tests with quiet verbosity
giangpham712 Aug 1, 2023
c0134ab
Exclude tables from crdb_internal and pg_extension
giangpham712 Aug 1, 2023
786e676
For CockroachDB, suppress transaction for DropForeignKeyOperation
giangpham712 Aug 3, 2023
c905195
When dropping user funcs, exclude from crdb_internal and pg_extension
giangpham712 Aug 3, 2023
b32cc9b
For CockroachDB, do not call unsupported func pg_indexam_has_property
giangpham712 Aug 3, 2023
cd1f5c9
Change verbosity level for running tests
giangpham712 Aug 3, 2023
7055e7e
Execute transaction in SERIALIZABLE isolation level for CockroachDB
giangpham712 Aug 3, 2023
502d410
Update build-cockroach workflow to run test againtst v23.1
giangpham712 Aug 3, 2023
e0f82ec
Use a different Northwind database script for CockroachDB
giangpham712 Aug 5, 2023
9bff187
Skip tests that hang for CockroachDB
giangpham712 Aug 6, 2023
ed1ceaa
Update build-cockroach to upload blame log file
giangpham712 Aug 6, 2023
8e62388
Fix build-cockroach.yml
giangpham712 Aug 6, 2023
60af85d
Update build-cockroach.yml
giangpham712 Aug 6, 2023
dacc06f
Update build-cockroach.yml
giangpham712 Aug 6, 2023
0e387eb
Increase test blame timeout
giangpham712 Aug 6, 2023
aa3b62c
Update build-cockroach.yml
giangpham712 Aug 7, 2023
acf54e3
Skip NodaTimeQueryNpgsqlTest for CockroachDB
giangpham712 Aug 7, 2023
548dff2
Add xunit configuration longRunningTestSeconds
giangpham712 Aug 7, 2023
946a96c
Add xunit configuration diagnosticMessages
giangpham712 Aug 7, 2023
2d9c753
Update BatchingTest to not use Version field as concurrency token column
giangpham712 Aug 7, 2023
75a2c86
Set xunit configuration maxParallelThreads to 1
giangpham712 Aug 7, 2023
027676b
Increase blame-hang-timeout
giangpham712 Aug 7, 2023
7a77563
Update build-cockroach.yml. Disable test parallelization
giangpham712 Aug 8, 2023
1aa4334
Fix build-cockroach.yml
giangpham712 Aug 8, 2023
717e985
Skip CitextQueryTest, RangeQueryNpgsqlTest, LTreeQueryTest, NetworkQu…
giangpham712 Aug 8, 2023
4bd9769
Add UseCockroachDb to NpgsqlDbContextOptions
giangpham712 Aug 14, 2023
b072087
Avoid using unsupported xmin column and JSON column type for CockroachDB
giangpham712 Aug 16, 2023
84f1043
Workaround to reset identity for truncated table for CockroachDB
giangpham712 Aug 28, 2023
e4c289f
Remove use of unsupported function pg_terminate_backend for CockroachDB
giangpham712 Aug 28, 2023
1b1002c
Update NpgsqlTestStore to target CockroachDB for better compatibility
giangpham712 Aug 29, 2023
6b1a554
Skip tests in FullTextSearchDbFunctionsNpgsqlTest for CockroachDB
giangpham712 Aug 29, 2023
ae47be8
Skip tests in PrimitiveCollectionsQueryNpgsqlTest
giangpham712 Sep 2, 2023
ffeae1f
Skip tests in NorthwindSplitIncludeNoTrackingQueryNpgsqlTest
giangpham712 Sep 7, 2023
737541a
Skip tests in SqlExecutorNpgsqlTest that tests unsupported features
giangpham712 Sep 7, 2023
6948ba3
Skip tests in UdfDbFunctionNpgsqlTests that tests unsupported features
giangpham712 Sep 7, 2023
c8fa04c
Update MigrationsInfrastructureNpgsqlTest to target CockroachDB
giangpham712 Sep 7, 2023
b8246b6
Skip tests in Array tests that test unsupported features
giangpham712 Sep 7, 2023
5244c3b
Skip tests in FuzzyStringMatchQueryNpgsqlTest
giangpham712 Sep 7, 2023
a7317f1
Update SequenceEndToEndTest to add compatibility with CockroachDB
giangpham712 Sep 7, 2023
22f315f
Fix code for reseting sequence value in StoreValueGenerationNpgsqlTest
giangpham712 Sep 11, 2023
936b09e
Update test in JsonStringQueryTest to match with CockroachDB behavior
giangpham712 Sep 11, 2023
942c9ac
Skip GearsOfWarQuery tests that use infinity which is not well supported
giangpham712 Sep 12, 2023
c342de1
Fix error in ArrayArrayQueryTest
giangpham712 Sep 14, 2023
5b6fb60
Skip incompatible test in NonSharedPrimitiveCollectionsQueryNpgsqlTest
giangpham712 Sep 14, 2023
e5c99e1
Update test in NpgsqlMigrationsSqlGeneratorTest to be compatible
giangpham712 Sep 14, 2023
b8ce164
Update test in JsonDomQueryTest to be compatible
giangpham712 Sep 14, 2023
7eadb6e
Update tests in BuiltInDataTypesNpgsqlTest to ignore unsupported types
giangpham712 Sep 14, 2023
dd1a33b
Make IsCockroachDb virtual
giangpham712 Sep 14, 2023
37ad6d3
Skip OptimisticConcurrency tests due to incompatibility
giangpham712 Sep 14, 2023
c78847c
Update BuiltInDataTypesNpgsqlTest to be compatible with CockroachDB
giangpham712 Sep 16, 2023
9b3d9c4
Skip tests in GearOfWearQuery that fail due to incompatibility
giangpham712 Sep 17, 2023
7ce59d6
Skip test in CharacterQueryNpgsqlTest due to different behavior
giangpham712 Sep 17, 2023
ca4d4ee
Skip test in CompatibilityQueryNpgsqlTest that tests Redshift
giangpham712 Sep 17, 2023
a582596
Skip tests in TrigramsQueryNpgsqlTest that test unsupported features
giangpham712 Sep 17, 2023
a56b8fd
Skip test in SystemColumnTest that tests unsupported xmin column
giangpham712 Sep 17, 2023
cf9d616
Update NpgsqlDatabaseCreatorTest to target CockroachDB for compatibility
giangpham712 Sep 17, 2023
b514595
Update DefaultValuesTest to target CockroachDB for compatibility
giangpham712 Sep 17, 2023
36e2084
Skip NorthwindDbFunctionsQuery tests that test unsupported features
giangpham712 Sep 17, 2023
a7709ee
Skip NorthwindFunctionsQuery tests that test unsupported features
giangpham712 Sep 17, 2023
850df9a
Skip tests in NorthwindAggregateOperatorsQuery due to known issues
giangpham712 Sep 17, 2023
d083534
Skip Northwind tests that fail due to known issues
giangpham712 Sep 17, 2023
9f91c29
Update and skip tests in TimestampQueryTest
giangpham712 Sep 17, 2023
1d6c7df
Update NpgsqlMigrationSqlGenerator to be compatible with CockroachDB
giangpham712 Sep 17, 2023
279343a
Update NpgsqlDatabaseCleaner to be compatible with CockroachDB
giangpham712 Sep 17, 2023
a7e9c1d
Update NpgsqlDatabaseModelFactory to be compatible with CockroachDB
giangpham712 Sep 17, 2023
e8a0280
Update tests in NpgsqlDatabaseModelFactoryTest to be compatible
giangpham712 Sep 28, 2023
d721073
Workaround in NpgsqlDatabaseCreator to resolve Cockroach incompatibility
giangpham712 Oct 4, 2023
7f46530
Skip tests in MigrationsNpgsqlTest that test unsupported features
giangpham712 Oct 4, 2023
15c1c99
Update tests in MigrationsNpgsqlTest to be compatible with CockroachDB
giangpham712 Oct 4, 2023
283bbf7
Update build-cockroach.yml
giangpham712 Oct 5, 2023
942e97d
Fix merge issues
giangpham712 Oct 5, 2023
2bf27a9
Fix PrimitiveCollectionsQueryNpgsqlTest
giangpham712 Oct 5, 2023
ef41515
Skip test with incompatibility in FullTextSearchDbFunctionsNpgsqlTest
giangpham712 Oct 5, 2023
2ed60c4
Skip incompatible tests in MigrationsNpgsqlTest
giangpham712 Oct 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions .github/workflows/build-cockroach.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
name: Build Cockroach

on:
push:
branches:
- cockroach
tags:
- v*
pull_request:
workflow_dispatch:

env:
dotnet_sdk_version: '8.0.100-preview.2.23153.6'
postgis_version: 3
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-22.04 ]
crdb_major: [ v23.1 ]
config: [ Release ]
# include:
# - os: ubuntu-22.04
# crdb_major: v23.1.3
# config: Debug
outputs:
is_release: ${{ steps.analyze_tag.outputs.is_release }}
is_prerelease: ${{ steps.analyze_tag.outputs.is_prerelease }}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.dotnet_sdk_version }}

- name: Build
run: dotnet build --configuration Debug
shell: bash

- name: Start CockroachDB ${{ matrix.crdb_major }} (Linux)
if: startsWith(matrix.os, 'ubuntu')
run: |
# First uninstall any cockroachDB installed on the image
sudo rm -f /usr/local/bin/cockroach
# Install CRDB

if [[ ${{ matrix.crdb_major }} == "master" ]]; then
wget --no-verbose -O cockroach https://edge-binaries.cockroachdb.com/cockroach/cockroach.linux-gnu-amd64.LATEST
chmod u+x cockroach
sudo mv ./cockroach /usr/local/bin/cockroach
elif [[ ${{ matrix.crdb_major }} == "v23.1" ]]; then
wget --no-verbose -O cockroach https://edge-binaries.cockroachdb.com/cockroach/cockroach.linux-gnu-amd64.release-23.1
chmod u+x cockroach
sudo mv ./cockroach /usr/local/bin/cockroach
else
curl https://binaries.cockroachdb.com/cockroach-v23.1.3.linux-amd64.tgz | tar -xz && sudo cp -i cockroach-v23.1.3.linux-amd64/cockroach /usr/local/bin/
sudo mkdir -p /usr/local/lib/cockroach
sudo cp -i cockroach-v23.1.3.linux-amd64/lib/libgeos.so /usr/local/lib/cockroach/
sudo cp -i cockroach-v23.1.3.linux-amd64/lib/libgeos_c.so /usr/local/lib/cockroach/
fi

which cockroach
cockroach version
# Create certificates
rm -rf cockroach-data
cockroach cert create-ca --certs-dir=certs --ca-key=certs/ca.key
cockroach cert create-client --certs-dir=certs --ca-key=certs/ca.key root
cockroach cert create-node --certs-dir=certs --ca-key=certs/ca.key 127.0.0.1 127.0.0.1
# Start the initialization
cockroach start-single-node --certs-dir=certs --advertise-addr=127.0.0.1:26257 --background
cockroach sql --certs-dir=certs -e "CREATE USER crdb_tests WITH PASSWORD 'crdb_tests'; GRANT admin TO crdb_tests" --url="postgresql://root@127.0.0.1:26257/defaultdb?sslcert=certs%2Fclient.root.crt&sslkey=certs%2Fclient.root.key&sslmode=verify-full&sslrootcert=certs%2Fca.crt"

- name: Test
run: TEST_COCKROACH_DB=true dotnet test -c ${{ matrix.config }} --blame-hang-timeout 600000 --blame-hang-dump-type mini --logger "GitHubActions;report-warnings=false"
shell: bash

- uses: actions/upload-artifact@v3
if: always()
with:
name: results
retention-days: 1
path: test/EFCore.PG.FunctionalTests/TestResults/**/*

- id: analyze_tag
name: Analyze tag
shell: bash
run: |
if [[ ${{ github.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "Release tag detected"
echo "::set-output name=is_release::true"
if [[ ${{ github.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+.*- ]]; then
echo "Prerelease tag detected"
echo "::set-output name=is_prerelease::true"
fi
fi

publish-ci:
needs: build
runs-on: ubuntu-22.04
if: github.event_name == 'push' && startsWith(github.repository, 'npgsql/')
environment: myget

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.dotnet_sdk_version }}

- name: Pack
run: dotnet pack --configuration Release --property:PackageOutputPath="$PWD/nupkgs" --version-suffix "ci.$(date -u +%Y%m%dT%H%M%S)+sha.${GITHUB_SHA:0:9}" -p:ContinuousIntegrationBuild=true

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: EFCore.PG.CI
path: nupkgs

- name: Publish packages to MyGet (vnext)
if: startsWith(github.ref, 'refs/heads/') && startsWith(github.ref, 'refs/heads/hotfix/') == false
run: dotnet nuget push "*.nupkg" --api-key ${{ secrets.MYGET_FEED_TOKEN }} --source https://www.myget.org/F/npgsql-vnext/api/v3/index.json
working-directory: nupkgs

- name: Publish packages to MyGet (patch)
if: startsWith(github.ref, 'refs/heads/hotfix/')
run: dotnet nuget push "*.nupkg" --api-key ${{ secrets.MYGET_FEED_TOKEN }} --source https://www.myget.org/F/npgsql/api/v3/index.json
working-directory: nupkgs

release:
needs: build
runs-on: ubuntu-22.04
if: github.event_name == 'push' && startsWith(github.repository, 'npgsql/') && needs.build.outputs.is_release == 'true'
environment: nuget.org

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.dotnet_sdk_version }}

- name: Pack
run: dotnet pack --configuration Release --property:PackageOutputPath="$PWD/nupkgs" -p:ContinuousIntegrationBuild=true

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: EFCore.PG.Release
path: nupkgs

# TODO: Create a release

- name: Publish to nuget.org
run: dotnet nuget push "*.nupkg" --api-key ${{ secrets.NUGET_ORG_API_KEY }} --source https://api.nuget.org/v3/index.json
working-directory: nupkgs
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>
<Project>
<PropertyGroup>
<EFCoreVersion>8.0.0-rc.2.23465.12</EFCoreVersion>
<MicrosoftExtensionsVersion>8.0.0-rc.2.23465.13</MicrosoftExtensionsVersion>
<NpgsqlVersion>8.0.0-preview.4</NpgsqlVersion>
<NpgsqlVersion>8.0.0-preview.5-ci.20230725T094520</NpgsqlVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
12 changes: 12 additions & 0 deletions src/EFCore.PG/Extensions/NpgsqlConnectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Npgsql.EntityFrameworkCore.PostgreSQL.Extensions;

internal static class NpgsqlConnectionExtensions
{
internal static bool IsCockroachDb(this NpgsqlConnection connection)
{
return connection.PostgresParameters.TryGetValue("crdb_version", out var _);
}
}
14 changes: 13 additions & 1 deletion src/EFCore.PG/Extensions/NpgsqlDatabaseFacadeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Data.Common;
using Npgsql.EntityFrameworkCore.PostgreSQL.Extensions;
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal;
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal;

Expand Down Expand Up @@ -53,4 +54,15 @@ private static IRelationalDatabaseFacadeDependencies GetFacadeDependencies(Datab

throw new InvalidOperationException(RelationalStrings.RelationalNotInUse);
}
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public static bool IsCockroachDb(this DatabaseFacade database)
{
return database.GetDbConnection() is NpgsqlConnection connection && connection.IsCockroachDb();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public interface INpgsqlSingletonOptions : ISingletonOptions
/// </summary>
bool UseRedshift { get; }

/// <summary>
/// Whether to target CockroachDB.
/// </summary>
bool UseCockroachDb { get; }

/// <summary>
/// Whether reverse null ordering is enabled.
/// </summary>
Expand Down
39 changes: 38 additions & 1 deletion src/EFCore.PG/Infrastructure/Internal/NpgsqlOptionsExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public virtual bool IsPostgresVersionSet
/// </summary>
public virtual bool UseRedshift { get; private set; }

/// <summary>
/// Whether to target CockroachDB.
/// </summary>
public virtual bool UseCockroachDb { get; private set; }

/// <summary>
/// The list of range mappings specified by the user.
/// </summary>
Expand Down Expand Up @@ -96,6 +101,7 @@ public NpgsqlOptionsExtension(NpgsqlOptionsExtension copyFrom) : base(copyFrom)
AdminDatabase = copyFrom.AdminDatabase;
_postgresVersion = copyFrom._postgresVersion;
UseRedshift = copyFrom.UseRedshift;
UseCockroachDb = copyFrom.UseCockroachDb;
_userRangeDefinitions = new List<UserRangeDefinition>(copyFrom._userRangeDefinitions);
ProvideClientCertificatesCallback = copyFrom.ProvideClientCertificatesCallback;
RemoteCertificateValidationCallback = copyFrom.RemoteCertificateValidationCallback;
Expand Down Expand Up @@ -221,6 +227,22 @@ public virtual NpgsqlOptionsExtension WithRedshift(bool useRedshift)
return clone;
}

/// <summary>
/// Returns a copy of the current instance with the specified CockroachDB settings.
/// </summary>
/// <param name="useCockroachDb">Whether to target CockroachDB.</param>
/// <returns>
/// A copy of the current instance with the specified CockroachDB setting.
/// </returns>
public virtual NpgsqlOptionsExtension WithCockroachDb(bool useCockroachDb)
{
var clone = (NpgsqlOptionsExtension)Clone();

clone.UseCockroachDb = useCockroachDb;

return clone;
}

/// <summary>
/// Returns a copy of the current instance configured with the specified value..
/// </summary>
Expand Down Expand Up @@ -268,6 +290,11 @@ public override void Validate(IDbContextOptions options)
{
throw new InvalidOperationException($"{nameof(UseRedshift)} and {nameof(PostgresVersion)} cannot both be set");
}

if (UseCockroachDb && UseRedshift)
{
throw new InvalidOperationException($"{nameof(UseCockroachDb)} and {nameof(UseRedshift)} cannot both be set");
}
}

#region Authentication
Expand Down Expand Up @@ -368,6 +395,11 @@ public override string LogFragment
builder.Append(nameof(Extension.UseRedshift)).Append(' ');
}

if (Extension.UseCockroachDb)
{
builder.Append(nameof(Extension.UseCockroachDb)).Append(' ');
}

if (Extension.ProvideClientCertificatesCallback is not null)
{
builder.Append(nameof(Extension.ProvideClientCertificatesCallback)).Append(" ");
Expand Down Expand Up @@ -437,6 +469,7 @@ public override int GetServiceProviderHashCode()
hashCode.Add(Extension.AdminDatabase);
hashCode.Add(Extension.PostgresVersion);
hashCode.Add(Extension.UseRedshift);
hashCode.Add(Extension.UseCockroachDb);
hashCode.Add(Extension.ProvideClientCertificatesCallback);
hashCode.Add(Extension.RemoteCertificateValidationCallback);
hashCode.Add(Extension.ProvidePasswordCallback);
Expand All @@ -454,7 +487,8 @@ public override bool ShouldUseSameServiceProvider(DbContextOptionsExtensionInfo
&& ReferenceEquals(Extension.DataSource, otherInfo.Extension.DataSource)
&& Extension.ReverseNullOrdering == otherInfo.Extension.ReverseNullOrdering
&& Extension.UserRangeDefinitions.SequenceEqual(otherInfo.Extension.UserRangeDefinitions)
&& Extension.UseRedshift == otherInfo.Extension.UseRedshift;
&& Extension.UseRedshift == otherInfo.Extension.UseRedshift
&& Extension.UseCockroachDb == otherInfo.Extension.UseCockroachDb;

/// <inheritdoc />
public override void PopulateDebugInfo(IDictionary<string, string> debugInfo)
Expand All @@ -468,6 +502,9 @@ public override void PopulateDebugInfo(IDictionary<string, string> debugInfo)
debugInfo["Npgsql.EntityFrameworkCore.PostgreSQL:" + nameof(NpgsqlDbContextOptionsBuilder.UseRedshift)]
= Extension.UseRedshift.GetHashCode().ToString(CultureInfo.InvariantCulture);

debugInfo["Npgsql.EntityFrameworkCore.PostgreSQL:" + nameof(NpgsqlDbContextOptionsBuilder.UseCockroachDb)]
= Extension.UseCockroachDb.GetHashCode().ToString(CultureInfo.InvariantCulture);

debugInfo["Npgsql.EntityFrameworkCore.PostgreSQL:" + nameof(NpgsqlDbContextOptionsBuilder.ReverseNullOrdering)]
= Extension.ReverseNullOrdering.GetHashCode().ToString(CultureInfo.InvariantCulture);

Expand Down
8 changes: 8 additions & 0 deletions src/EFCore.PG/Infrastructure/NpgsqlDbContextOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public virtual NpgsqlDbContextOptionsBuilder SetPostgresVersion(int major, int m
public virtual NpgsqlDbContextOptionsBuilder UseRedshift(bool useRedshift = true)
=> WithOption(e => e.WithRedshift(useRedshift));

/// <summary>
/// Configures the provider to work in CockroachDB compatibility mode, which avoids certain unsupported features from modern
/// PostgreSQL versions.
/// </summary>
/// <param name="useCockroachDb">Whether to target CockroachDB.</param>
public virtual NpgsqlDbContextOptionsBuilder UseCockroachDb(bool useCockroachDb = true)
=> WithOption(e => e.WithCockroachDb(useCockroachDb));

/// <summary>
/// Maps a user-defined PostgreSQL range type for use.
/// </summary>
Expand Down
17 changes: 17 additions & 0 deletions src/EFCore.PG/Internal/NpgsqlSingletonOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public class NpgsqlSingletonOptions : INpgsqlSingletonOptions
/// </summary>
public virtual bool UseRedshift { get; private set; }

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual bool UseCockroachDb { get; private set; }

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
Expand Down Expand Up @@ -81,6 +89,7 @@ public virtual void Initialize(IDbContextOptions options)
PostgresVersion = npgsqlOptions.PostgresVersion;
IsPostgresVersionSet = npgsqlOptions.IsPostgresVersionSet;
UseRedshift = npgsqlOptions.UseRedshift;
UseCockroachDb = npgsqlOptions.UseCockroachDb;
ReverseNullOrderingEnabled = npgsqlOptions.ReverseNullOrdering;
UserRangeDefinitions = npgsqlOptions.UserRangeDefinitions;

Expand Down Expand Up @@ -111,6 +120,14 @@ public virtual void Validate(IDbContextOptions options)
nameof(DbContextOptionsBuilder.UseInternalServiceProvider)));
}

if (UseCockroachDb != npgsqlOptions.UseCockroachDb)
{
throw new InvalidOperationException(
CoreStrings.SingletonOptionChanged(
nameof(NpgsqlDbContextOptionsBuilder.UseCockroachDb),
nameof(DbContextOptionsBuilder.UseInternalServiceProvider)));
}

if (ReverseNullOrderingEnabled != npgsqlOptions.ReverseNullOrdering)
{
throw new InvalidOperationException(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal;

namespace Npgsql.EntityFrameworkCore.PostgreSQL.Metadata.Conventions;

/// <summary>
Expand Down Expand Up @@ -71,6 +73,11 @@ protected virtual void DiscoverPostgresExtensions(
/// </summary>
protected virtual void ProcessRowVersionProperty(IConventionProperty property, RelationalTypeMapping typeMapping)
{
if (_typeMappingSource is NpgsqlTypeMappingSource { IsCockroachDb: true })
{
return;
}

if (property is { ValueGenerated: ValueGenerated.OnAddOrUpdate, IsConcurrencyToken: true }
&& typeMapping.StoreType == "xid")
{
Expand Down
Loading