-
Notifications
You must be signed in to change notification settings - Fork 256
Fix migration bug with PostgreSQL 9.5 #607
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 27 additions & 3 deletions
30
test/EFCore.PG.FunctionalTests/TestUtilities/NpgsqlTestHelpers.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,45 @@ | ||
| using Microsoft.EntityFrameworkCore; | ||
| using System; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using Microsoft.EntityFrameworkCore.TestUtilities; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Xunit; | ||
|
|
||
| namespace Npgsql.EntityFrameworkCore.PostgreSQL.TestUtilities | ||
| { | ||
| public class NpgsqlTestHelpers : TestHelpers | ||
| { | ||
| protected NpgsqlTestHelpers() | ||
| Version _postgresVersion; | ||
|
|
||
| public class VersionScope : IDisposable | ||
| { | ||
| NpgsqlTestHelpers _helpers; | ||
| Version _oldVersion, _newVersion; | ||
|
|
||
| internal VersionScope(NpgsqlTestHelpers helpers, Version version) | ||
| { | ||
| _helpers = helpers; | ||
| _oldVersion = helpers._postgresVersion; | ||
| _newVersion = helpers._postgresVersion = version; | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| Assert.Equal(_helpers._postgresVersion, _newVersion); | ||
| _helpers._postgresVersion = _oldVersion; | ||
| } | ||
| } | ||
|
|
||
| public VersionScope WithPostgresVersion(Version version) => new VersionScope(this, version); | ||
|
|
||
| protected NpgsqlTestHelpers() {} | ||
|
|
||
| public static NpgsqlTestHelpers Instance { get; } = new NpgsqlTestHelpers(); | ||
|
|
||
| public override IServiceCollection AddProviderServices(IServiceCollection services) | ||
| => services.AddEntityFrameworkNpgsql(); | ||
|
|
||
| protected override void UseProviderOptions(DbContextOptionsBuilder optionsBuilder) | ||
| => optionsBuilder.UseNpgsql(new NpgsqlConnection("Database=DummyDatabase")); | ||
| => optionsBuilder.UseNpgsql(new NpgsqlConnection("Database=DummyDatabase"), | ||
| options => options.SetPostgresVersion(_postgresVersion)); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to simply call
base.Generate()with aCreateSequenceOperationthat has ClrType overridden to long? This would prevent the duplication of that code in this function...(@austindrenski it's better to wait for me to review too, I know I'm a bit busy these days but still...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@roji Apologies on moving forward with the merge before your review. I'll open a follow-up PR to de-duplicate where possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@roji How would you suggest to clone
CreateSequenceOperation operationclass with all it's properties? Or you suggest modify its ClrType property "in-place" and return back to original value after calling base.Generate() method?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing in-place is a possibility, yes. I'm not even sure it's necessary to return back to the original value as these operations are only used for SQL generation - but for correctness's sake it's a good idea.
You could also copy properties one-by-one to a new instance, including annotations, but that would be tedious and brittle in case something gets added in the future.