Permalink
Browse files

New CurrentUser SystemMethod and implemented for Postgres

Uses the current_user function in Postgres as the the default value.
  • Loading branch information...
1 parent 99d3e87 commit d24c500d9092a336ca6153994853df63264b455a @daniellee committed Dec 6, 2012
@@ -46,6 +46,8 @@ protected override string FormatSystemMethods(SystemMethods systemMethod)
return "now()";
case SystemMethods.CurrentUTCDateTime:
return "(now() at time zone 'UTC')";
+ case SystemMethods.CurrentUser:
+ return "current_user";
}
throw new NotImplementedException();
@@ -609,18 +609,29 @@ private DeleteTableExpression GetDeleteTableExpression(string tableName)
[Test]
public void CanUseSystemMethodCurrentUTCDateTimeAsADefaultValueForAColumn()
{
- string tableName = "NewTable";
+ const 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;
+ var expression = new CreateColumnExpression {Column = columnDefinition, 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')");
}
+ [Test]
+ public void CanUseSystemMethodCurrentUserAsADefaultValueForAColumn()
+ {
+ const string tableName = "NewTable";
+
+ var columnDefinition = new ColumnDefinition { Name = "NewColumn", Size = 15, Type = DbType.String, DefaultValue = SystemMethods.CurrentUser };
+
+ var expression = new CreateColumnExpression {Column = columnDefinition, TableName = tableName};
+
+ string sql = generator.Generate(expression);
+ sql.ShouldBe("ALTER TABLE \"public\".\"NewTable\" ADD \"NewColumn\" varchar(15) NOT NULL DEFAULT current_user");
+ }
+
private CreateTableExpression GetCreateTableExpression(string tableName)
{
string columnName1 = "ColumnName1";
@@ -6,6 +6,7 @@ public enum SystemMethods
NewGuid,
NewSequentialId,
CurrentDateTime,
- CurrentUTCDateTime
+ CurrentUTCDateTime,
+ CurrentUser
}
}

0 comments on commit d24c500

Please sign in to comment.