Skip to content

Commit cfa61c9

Browse files
committed
Fix schema validator for Npgsql 5+
1 parent 9bcac48 commit cfa61c9

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
6565
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
6666
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="8.5.2" />
67-
<PackageReference Include="Npgsql" Version="4.1.9" />
67+
<PackageReference Include="Npgsql" Version="6.0.2" />
6868
<PackageReference Include="MySql.Data" Version="8.0.27" />
6969
</ItemGroup>
7070
<ItemGroup Condition="$(NhNetFx)">

src/NHibernate/Dialect/Schema/PostgreSQLMetadata.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,39 @@ public PostgreSQLColumnMetadata(DataRow rs)
138138
this.SetNumericalPrecision(rs["NUMERIC_PRECISION"]);
139139

140140
Nullable = Convert.ToString(rs["IS_NULLABLE"]);
141-
TypeName = Convert.ToString(rs["DATA_TYPE"]);
141+
TypeName = Normalize(Convert.ToString(rs["DATA_TYPE"]));
142+
}
143+
144+
private static string Normalize(string typeName)
145+
{
146+
switch (typeName)
147+
{
148+
case "double precision":
149+
return "float8";
150+
case "real":
151+
return "float4";
152+
case "smallint":
153+
return "int2";
154+
case "integer":
155+
return "int4";
156+
case "bigint":
157+
return "int8";
158+
}
159+
160+
if (typeName.EndsWith("with timezone"))
161+
{
162+
return (typeName.StartsWith("timestamp")
163+
? typeName.Replace("timestamp", "timestamptz")
164+
: typeName.Replace("time", "timetz"))
165+
.Replace("with timezone", "").Trim();
166+
}
167+
168+
if (typeName.EndsWith("without timezone"))
169+
{
170+
return typeName.Replace("without timezone", "").Trim();
171+
}
172+
173+
return typeName;
142174
}
143175
}
144176

0 commit comments

Comments
 (0)