Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class PostgreSQLTransformationProvider_GetColumnsDefaultTypeTests : Postg
private const decimal DecimalDefaultValue = 14.56565m;

[Test]
public void GetColumns_DataTypeResolveSucceeds()
public void GetColumns_DefaultValues_Succeeds()
{
// Arrange
var dateTimeDefaultValue = new DateTime(2000, 1, 2, 3, 4, 5, DateTimeKind.Utc);
Expand Down Expand Up @@ -71,4 +71,48 @@ public void GetColumns_DataTypeResolveSucceeds()
Assert.That(stringColumn1.DefaultValue, Is.EqualTo("Hello"));
Assert.That(binarycolumn1.DefaultValue, Is.EqualTo(new byte[] { 12, 32, 34 }));
}

// 1 will coerce to true on inserts but not for default values in Postgre SQL - same for 0 to false
// so we do not test it here
[TestCase("true", true)]
[TestCase("TRUE", true)]
[TestCase("t", true)]
[TestCase("T", true)]
[TestCase("yes", true)]
[TestCase("YES", true)]
[TestCase("y", true)]
[TestCase("Y", true)]
[TestCase("on", true)]
[TestCase("ON", true)]
[TestCase("false", false)]
[TestCase("FALSE", false)]
[TestCase("f", false)]
[TestCase("F", false)]
[TestCase("false", false)]

Choose a reason for hiding this comment

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

doppelt

[TestCase("FALSE", false)]

Choose a reason for hiding this comment

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

doppelt

[TestCase("n", false)]
[TestCase("N", false)]
[TestCase("off", false)]
[TestCase("OFF", false)]
public void GetColumns_DefaultValueBooleanValues_Succeeds(object inboundBooleanDefaultValue, bool outboundBooleanDefaultValue)
{
// Arrange
var dateTimeDefaultValue = new DateTime(2000, 1, 2, 3, 4, 5, DateTimeKind.Utc);
var guidDefaultValue = Guid.NewGuid();

const string testTableName = "MyDefaultTestTable";
const string booleanColumnName1 = "booleancolumn1";

Provider.AddTable(testTableName,
new Column(booleanColumnName1, DbType.Boolean) { DefaultValue = inboundBooleanDefaultValue }
);

// Act
var columns = Provider.GetColumns(testTableName);

// Assert
var booleanColumn1 = columns.Single(x => x.Name == booleanColumnName1);

Assert.That(booleanColumn1.DefaultValue, Is.EqualTo(outboundBooleanDefaultValue));
}
}
2 changes: 1 addition & 1 deletion src/Migrator/Framework/Column.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public object DefaultValue
{
if (defaultValueDateTime.Kind != DateTimeKind.Utc)
{
throw new Exception("We only accept UTC values as default DateTime values.");
throw new Exception("Only UTC values are accepted as default DateTime values.");
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/Migrator/Providers/TransformationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,9 @@

public virtual void ChangeColumn(string table, Column column)
{
var isUniqueSet = column.ColumnProperty.IsSet(ColumnProperty.Unique);

Check warning on line 537 in src/Migrator/Providers/TransformationProvider.cs

View workflow job for this annotation

GitHub Actions / build

'ColumnProperty.Unique' is obsolete: 'Use method 'AddUniqueConstraint' instead. This is marked being obsolete since you cannot add a name for the constraint which makes it difficult to remove the constraint again.'

column.ColumnProperty = column.ColumnProperty.Clear(ColumnProperty.Unique);

Check warning on line 539 in src/Migrator/Providers/TransformationProvider.cs

View workflow job for this annotation

GitHub Actions / build

'ColumnProperty.Unique' is obsolete: 'Use method 'AddUniqueConstraint' instead. This is marked being obsolete since you cannot add a name for the constraint which makes it difficult to remove the constraint again.'

var mapper = _dialect.GetAndMapColumnProperties(column);

Expand Down Expand Up @@ -1721,6 +1721,7 @@
{
return Dialect.Quote(name);
}

return name;
}

Expand All @@ -1730,6 +1731,7 @@
{
return Dialect.Quote(name);
}

return name;
}

Expand Down Expand Up @@ -1793,7 +1795,7 @@
}

table = QuoteTableNameIfRequired(table);
column = this.QuoteColumnNameIfRequired(column);
column = QuoteColumnNameIfRequired(column);
var def = Dialect.Default(defaultValue);
ExecuteNonQuery(string.Format("ALTER TABLE {0} ADD DEFAULT('{1}') FOR {2}", table, def, column));
}
Expand Down
Loading