-
Notifications
You must be signed in to change notification settings - Fork 934
WIP Fix validating similar but not equal column types #2997
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
Open
hazzik
wants to merge
6
commits into
nhibernate:master
Choose a base branch
from
hazzik:gh1895
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
084ca8a
Fix validating similar column types
hazzik abf1d11
Fix issue with case and Turkish culture
hazzik 375c032
Display validation errors
hazzik 7ad074d
Improve error message for SchemaValidationException
hazzik 4e071d8
Aesthetic change to the error message
hazzik fe20c5f
Oracle, go home, you're drunk
hazzik 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
101 changes: 101 additions & 0 deletions
101
src/NHibernate.Test/Async/Tools/hbm2ddl/SchemaValidator/PostgresSchemaValidateFixture.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 |
---|---|---|
@@ -0,0 +1,101 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using System; | ||
using NHibernate.Cfg; | ||
using NHibernate.Dialect; | ||
using NHibernate.Mapping.ByCode; | ||
using NHibernate.Tool.hbm2ddl; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.Tools.hbm2ddl.SchemaValidator | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class PostgresSchemaValidateFixtureAsync | ||
{ | ||
[Test] | ||
public async Task ShouldBeInvalidIfTimestampTzIsExpectedAndGotTimestampAsync() | ||
{ | ||
var actual = BuildConfiguration("timestamp"); | ||
Assume.That(Dialect.Dialect.GetDialect(actual.Properties) is PostgreSQLDialect); | ||
|
||
var expected = BuildConfiguration("timestamptz"); | ||
|
||
var export = new SchemaExport(actual); | ||
await (export.CreateAsync(true, true)); | ||
|
||
try | ||
{ | ||
var validator = new Tool.hbm2ddl.SchemaValidator(expected); | ||
|
||
var error = Assert.ThrowsAsync<SchemaValidationException>(() => validator.ValidateAsync()); | ||
Assert.That(error, Has.Message.StartsWith("Schema validation failed: see list of validation errors")); | ||
Assert.That( | ||
error, | ||
Has.Property("ValidationErrors").Some.Contains("Wrong column type").IgnoreCase | ||
.And.Contains("for column CreatedAt. Found: timestamp, Expected timestamptz").IgnoreCase); | ||
} | ||
finally | ||
{ | ||
await (export.DropAsync(true, true)); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task ShouldBeInvalidIfTimestampIsExpectedAndGotTimestampTzAsync() | ||
{ | ||
var actual = BuildConfiguration("timestamptz"); | ||
Assume.That(Dialect.Dialect.GetDialect(actual.Properties) is PostgreSQLDialect); | ||
|
||
var expected = BuildConfiguration("timestamp"); | ||
|
||
var export = new SchemaExport(actual); | ||
await (export.CreateAsync(true, true)); | ||
|
||
try | ||
{ | ||
var validator = new Tool.hbm2ddl.SchemaValidator(expected); | ||
|
||
var error = Assert.ThrowsAsync<SchemaValidationException>(() => validator.ValidateAsync()); | ||
Assert.That(error, Has.Message.StartsWith("Schema validation failed: see list of validation errors")); | ||
Assert.That( | ||
error, | ||
Has.Property("ValidationErrors").Some.Contains("Wrong column type").IgnoreCase | ||
.And.Contains("for column CreatedAt. Found: timestamptz, Expected timestamp").IgnoreCase); | ||
} | ||
finally | ||
{ | ||
await (export.DropAsync(true, true)); | ||
} | ||
} | ||
|
||
private static Configuration BuildConfiguration(string type) | ||
{ | ||
var mapper = new ModelMapper(); | ||
mapper.Class<Entity>(c => | ||
{ | ||
c.Table("Entity"); | ||
c.Id(x => x.Id); | ||
c.Property(x => x.CreatedAt, p => p.Column(cm => cm.SqlType(type))); | ||
}); | ||
|
||
var cfg = TestConfigurationHelper.GetDefaultConfiguration(); | ||
cfg.AddDeserializedMapping(mapper.CompileMappingForAllExplicitlyAddedEntities(), "Entity"); | ||
return cfg; | ||
} | ||
|
||
public class Entity | ||
{ | ||
public virtual int Id { get; set; } | ||
public virtual DateTime CreatedAt { get; set; } | ||
} | ||
} | ||
} |
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
90 changes: 90 additions & 0 deletions
90
src/NHibernate.Test/Tools/hbm2ddl/SchemaValidator/PostgresSchemaValidateFixture.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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using NHibernate.Cfg; | ||
using NHibernate.Dialect; | ||
using NHibernate.Mapping.ByCode; | ||
using NHibernate.Tool.hbm2ddl; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.Tools.hbm2ddl.SchemaValidator | ||
{ | ||
[TestFixture] | ||
public class PostgresSchemaValidateFixture | ||
{ | ||
[Test] | ||
public void ShouldBeInvalidIfTimestampTzIsExpectedAndGotTimestamp() | ||
{ | ||
var actual = BuildConfiguration("timestamp"); | ||
Assume.That(Dialect.Dialect.GetDialect(actual.Properties) is PostgreSQLDialect); | ||
|
||
var expected = BuildConfiguration("timestamptz"); | ||
|
||
var export = new SchemaExport(actual); | ||
export.Create(true, true); | ||
|
||
try | ||
{ | ||
var validator = new Tool.hbm2ddl.SchemaValidator(expected); | ||
|
||
var error = Assert.Throws<SchemaValidationException>(() => validator.Validate()); | ||
Assert.That(error, Has.Message.StartsWith("Schema validation failed: see list of validation errors")); | ||
Assert.That( | ||
error, | ||
Has.Property("ValidationErrors").Some.Contains("Wrong column type").IgnoreCase | ||
.And.Contains("for column CreatedAt. Found: timestamp, Expected timestamptz").IgnoreCase); | ||
} | ||
finally | ||
{ | ||
export.Drop(true, true); | ||
} | ||
} | ||
|
||
[Test] | ||
public void ShouldBeInvalidIfTimestampIsExpectedAndGotTimestampTz() | ||
{ | ||
var actual = BuildConfiguration("timestamptz"); | ||
Assume.That(Dialect.Dialect.GetDialect(actual.Properties) is PostgreSQLDialect); | ||
|
||
var expected = BuildConfiguration("timestamp"); | ||
|
||
var export = new SchemaExport(actual); | ||
export.Create(true, true); | ||
|
||
try | ||
{ | ||
var validator = new Tool.hbm2ddl.SchemaValidator(expected); | ||
|
||
var error = Assert.Throws<SchemaValidationException>(() => validator.Validate()); | ||
Assert.That(error, Has.Message.StartsWith("Schema validation failed: see list of validation errors")); | ||
Assert.That( | ||
error, | ||
Has.Property("ValidationErrors").Some.Contains("Wrong column type").IgnoreCase | ||
.And.Contains("for column CreatedAt. Found: timestamptz, Expected timestamp").IgnoreCase); | ||
} | ||
finally | ||
{ | ||
export.Drop(true, true); | ||
} | ||
} | ||
|
||
private static Configuration BuildConfiguration(string type) | ||
{ | ||
var mapper = new ModelMapper(); | ||
mapper.Class<Entity>(c => | ||
{ | ||
c.Table("Entity"); | ||
c.Id(x => x.Id); | ||
c.Property(x => x.CreatedAt, p => p.Column(cm => cm.SqlType(type))); | ||
}); | ||
|
||
var cfg = TestConfigurationHelper.GetDefaultConfiguration(); | ||
cfg.AddDeserializedMapping(mapper.CompileMappingForAllExplicitlyAddedEntities(), "Entity"); | ||
return cfg; | ||
} | ||
|
||
public class Entity | ||
{ | ||
public virtual int Id { get; set; } | ||
public virtual DateTime CreatedAt { get; set; } | ||
} | ||
} | ||
} |
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
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
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.
Why not simply check that next char is not a letter (
char.IsLetter
)?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.
I was/am thinking about that. Even have code about to push. But it is not that simple.
Oracle is pouncing with (n)varchar/(n)varchar2...
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.
Still see no reasons to use regex - check additionally for not a digit (
char.IsDigit
). Alphanumeric character check should sufficeThere 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.
Yes, I hate the regex myself. But that is not that easy really. For example, Db2's
CHAR(16) FOR BIT DATA
would match toCHAR(16)
even in my implementation with regex.