Permalink
Browse files

Implemented CurrentDateTime SystemMethod for MySql

Using the CURRENT_TIMESTAMP function as default value.
  • Loading branch information...
1 parent d24c500 commit 70e5f838360d8f47c85e49c0dfed82e91c3420b8 @daniellee committed Dec 6, 2012
@@ -18,6 +18,12 @@ protected override string FormatIdentity(ColumnDefinition column)
protected override string FormatSystemMethods(SystemMethods systemMethod)
{
+ switch (systemMethod)
+ {
+ case SystemMethods.CurrentDateTime:
+ return "CURRENT_TIMESTAMP";
+ }
+
throw new NotImplementedException();
}
}
@@ -230,6 +230,7 @@
<Compile Include="Unit\Expressions\DeleteDefaultConstraintExpressionTests.cs" />
<Compile Include="Unit\Generators\GenericGenerator\GenericGeneratorTests.cs" />
<Compile Include="Unit\Generators\Firebird\FirebirdGeneratorTests.cs" />
+ <Compile Include="Unit\Generators\MySql\MySqlSystemMethodsTests.cs" />
<Compile Include="Unit\Generators\Oracle\OracleCreateSequenceTests.cs" />
<Compile Include="Unit\Generators\Postgres\PostgresDataTests.cs" />
<Compile Include="Unit\Generators\SqlServer2000\SqlServer2000GeneratorTests.cs" />
@@ -0,0 +1,32 @@
+using System.Data;
+using FluentMigrator.Expressions;
+using FluentMigrator.Model;
+using FluentMigrator.Runner.Generators.MySql;
+using NUnit.Framework;
+using NUnit.Should;
+
+namespace FluentMigrator.Tests.Unit.Generators.MySql
+{
+ [TestFixture]
+ public class MySqlSystemMethodsTests
+ {
+ private MySqlGenerator generator;
+
+ [SetUp]
+ public void SetUp()
+ {
+ generator = new MySqlGenerator();
+ }
+
+ [Test]
+ public void CanUseSystemMethodCurrentDateTimeAsADefaultValueForAColumn()
+ {
+ var columnDefinition = new ColumnDefinition { Name = "NewColumn", Size = 15, Type = null, CustomType = "TIMESTAMP", DefaultValue = SystemMethods.CurrentDateTime };
+ var expression = new CreateColumnExpression {Column = columnDefinition, TableName = "NewTable"};
+
+ string sql = generator.Generate(expression);
+
+ sql.ShouldBe("ALTER TABLE `NewTable` ADD COLUMN `NewColumn` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP");
+ }
+ }
+}

0 comments on commit 70e5f83

Please sign in to comment.