Skip to content

Commit 70c2bab

Browse files
lillo42fredericDelaporte
authored andcommitted
Fix SchemaValidator fails for PostgreSql sequences
Fixes #1163
1 parent 2572caf commit 70c2bab

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using NHibernate.Cfg.MappingSchema;
12+
using NHibernate.Mapping.ByCode;
13+
using NHibernate.Tool.hbm2ddl;
14+
using NUnit.Framework;
15+
16+
namespace NHibernate.Test.NHSpecificTest.GH1163
17+
{
18+
using System.Threading.Tasks;
19+
[TestFixture]
20+
public class FixtureAsync : TestCaseMappingByCode
21+
{
22+
protected override bool AppliesTo(Dialect.Dialect dialect)
23+
{
24+
return dialect.SupportsSequences;
25+
}
26+
27+
[Test]
28+
public async Task ValidateSequencesAsync()
29+
{
30+
var validator = new SchemaValidator(cfg);
31+
await (validator.ValidateAsync());
32+
}
33+
34+
protected override HbmMapping GetMappings()
35+
{
36+
var mapper = new ModelMapper();
37+
mapper.Class<Account>(m=>
38+
{
39+
m.Table("account");
40+
m.Id(x => x.Id, c =>
41+
{
42+
c.Column("account_id");
43+
c.Generator(Generators.Sequence, g => g.Params(new { sequence = "account_id_gen" }));
44+
});
45+
m.Property(x => x.Login, c => { c.Column("login_name"); c.NotNullable(true); });
46+
m.Property(x => x.PasswordHash, c => { c.Column("password_hash"); c.NotNullable(true); });
47+
m.Property(x => x.ValidFrom, c => { c.Column("valid_from"); c.NotNullable(true); });
48+
m.Property(x => x.ValidUntil, c => { c.Column("valid_until"); });
49+
});
50+
51+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
52+
}
53+
}
54+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.GH1163
4+
{
5+
public class Account
6+
{
7+
public virtual long? Id { get; set; }
8+
public virtual string Login { get; set; }
9+
public virtual string PasswordHash { get; set; }
10+
public virtual DateTime ValidFrom { get; set; }
11+
public virtual DateTime? ValidUntil { get; set; }
12+
}
13+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using NHibernate.Cfg.MappingSchema;
2+
using NHibernate.Mapping.ByCode;
3+
using NHibernate.Tool.hbm2ddl;
4+
using NUnit.Framework;
5+
6+
namespace NHibernate.Test.NHSpecificTest.GH1163
7+
{
8+
[TestFixture]
9+
public class Fixture : TestCaseMappingByCode
10+
{
11+
protected override bool AppliesTo(Dialect.Dialect dialect)
12+
{
13+
return dialect.SupportsSequences;
14+
}
15+
16+
[Test]
17+
public void ValidateSequences()
18+
{
19+
var validator = new SchemaValidator(cfg);
20+
validator.Validate();
21+
}
22+
23+
protected override HbmMapping GetMappings()
24+
{
25+
var mapper = new ModelMapper();
26+
mapper.Class<Account>(m=>
27+
{
28+
m.Table("account");
29+
m.Id(x => x.Id, c =>
30+
{
31+
c.Column("account_id");
32+
c.Generator(Generators.Sequence, g => g.Params(new { sequence = "account_id_gen" }));
33+
});
34+
m.Property(x => x.Login, c => { c.Column("login_name"); c.NotNullable(true); });
35+
m.Property(x => x.PasswordHash, c => { c.Column("password_hash"); c.NotNullable(true); });
36+
m.Property(x => x.ValidFrom, c => { c.Column("valid_from"); c.NotNullable(true); });
37+
m.Property(x => x.ValidUntil, c => { c.Column("valid_until"); });
38+
});
39+
40+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
41+
}
42+
}
43+
}

src/NHibernate/Dialect/PostgreSQLDialect.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ public override string CurrentTimestampSelectString
325325

326326
public override bool SupportsUnboundedLobLocatorMaterialization => false;
327327

328+
public override string QuerySequencesString => "SELECT c.relname FROM pg_class c WHERE c.relkind = 'S'";
329+
328330
#endregion
329331

330332
[Serializable]

0 commit comments

Comments
 (0)