Skip to content

Fix schema validator for Npgsql 5 #2992

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 1 commit into from
Jan 23, 2022
Merged

Fix schema validator for Npgsql 5 #2992

merged 1 commit into from
Jan 23, 2022

Conversation

hazzik
Copy link
Member

@hazzik hazzik commented Jan 16, 2022

Npgsql 5 returns different type names for some of the types. Normalize them back to what dialect expects.

Fixes #2876

@hazzik
Copy link
Member Author

hazzik commented Jan 16, 2022

Imo this is the least intrusive approach that works for both Npgsql 5 and Npgsql 4. I was considering doing the other way around (normalize to Npgsql 5 type system). But that require more changes and could be a breaking changes due to changes to the dialect for some users (if, eg, they do textual schema compare).

@hazzik hazzik changed the title WIP Fix schema validator for Npgsql 5+ Fix schema validator for Npgsql 5 Jan 16, 2022
@hazzik hazzik requested a review from bahusoid January 18, 2022 05:07
bahusoid
bahusoid previously approved these changes Jan 18, 2022
@hazzik
Copy link
Member Author

hazzik commented Jan 18, 2022

@bahusoid, @fredericDelaporte are you ok with including this to 5.3.x?

@hazzik hazzik removed the r: Fixed label Jan 18, 2022
@bahusoid
Copy link
Member

including this to 5.3.x

Yeah. Why not...

@hazzik hazzik changed the base branch from master to 5.3.x January 19, 2022 09:24
@hazzik
Copy link
Member Author

hazzik commented Jan 19, 2022

Yeah. Why not...

Rebased to 5.3.x

@hazzik hazzik added this to the 5.3.11 milestone Jan 19, 2022
@hazzik hazzik enabled auto-merge (squash) January 19, 2022 10:38
Comment on lines +146 to +158
switch (typeName)
{
case "double precision":
return "float8";
case "real":
return "float4";
case "smallint":
return "int2";
case "integer":
return "int4";
case "bigint":
return "int8";
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can see the naming changes in Npgsql change commit, or infer it from PostgreSQL documentation.

It looks like we were already having an issue with older Npgsql drivers, because we were using the complete name, boolean, while older drivers were previously supposed to yield the short name, bool. That trouble would be fixed since we do not translate it to its short name here.

But then we keep an inconsistency: the dialect and now the metadata are using PostgreSQL type short aliases for most types excepted for the boolean type.

For the same reasons than in this comment, normalizing this would be breaking. So, let it stay that way.


if (typeName.StartsWith("character", StringComparison.Ordinal))
{
return typeName.Replace("character varying", "varchar").Replace("character", "char");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is likely we are fixing another old trouble by the way here: for fixed length character types, the older Npgsql drivers could yield bpchar, while our dialects are using char.

@fredericDelaporte
Copy link
Member

I am used to the "auto-merge" feature on Azure DevOps, but not here on GitHub. It was quite a surprise for me. It lacks visibility I think.

@hazzik hazzik deleted the npgsql6 branch January 23, 2022 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Schema validation not working with NpgSql v5
3 participants