Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add CurrentUTCDateTime SystemMethod to Postgres

  • Loading branch information...
commit 99d3e870c86022d625274f486568340c156b2905 1 parent 021af65
@daniellee authored
View
2  src/FluentMigrator.Runner/Generators/Postgres/PostgresColumn.cs
@@ -44,6 +44,8 @@ protected override string FormatSystemMethods(SystemMethods systemMethod)
return "uuid_generate_v4()";
case SystemMethods.CurrentDateTime:
return "now()";
+ case SystemMethods.CurrentUTCDateTime:
+ return "(now() at time zone 'UTC')";
}
throw new NotImplementedException();
View
15 src/FluentMigrator.Tests/Unit/Generators/Postgres/PostgresGeneratorTests.cs
@@ -606,6 +606,21 @@ private DeleteTableExpression GetDeleteTableExpression(string tableName)
return new DeleteTableExpression { TableName = tableName };
}
+ [Test]
+ public void CanUseSystemMethodCurrentUTCDateTimeAsADefaultValueForAColumn()
+ {
+ string tableName = "NewTable";
+
+ var columnDefinition = new ColumnDefinition {Name = "NewColumn", Size = 5, Type = DbType.String, DefaultValue = SystemMethods.CurrentUTCDateTime};
+
+ var expression = new CreateColumnExpression();
+ expression.Column = columnDefinition;
+ expression.TableName = tableName;
+
+ string sql = generator.Generate(expression);
+ sql.ShouldBe("ALTER TABLE \"public\".\"NewTable\" ADD \"NewColumn\" varchar(5) NOT NULL DEFAULT (now() at time zone 'UTC')");
+ }
+
private CreateTableExpression GetCreateTableExpression(string tableName)
{
string columnName1 = "ColumnName1";
Please sign in to comment.
Something went wrong with that request. Please try again.