Skip to content

Commit

Permalink
migrations up working
Browse files Browse the repository at this point in the history
  • Loading branch information
caleblloyd committed Jun 27, 2017
1 parent 2f23062 commit 4b3ec79
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
3 changes: 2 additions & 1 deletion src/EFCore.MySql/EFCore.MySql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.0.0-preview3-*" />
<!--<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.0.0-preview3-*" />-->
<ProjectReference Include="../../../EntityFramework/src/EFCore.Relational/EFCore.Relational.csproj" />
<PackageReference Include="MySqlConnector" Version="0.20.*" />
<PackageReference Include="Pomelo.JsonObject" Version="1.1.1" />
</ItemGroup>
Expand Down
45 changes: 22 additions & 23 deletions src/EFCore.MySql/Migrations/MySqlMigrationsSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ protected override void ColumnDefinition([CanBeNull] string schema, [NotNull] st
}

var autoIncrement = false;
var annotations = model.GetAnnotations();
if (annotations.Any(a => a.Name == "MySql:ValueGenerationStrategy") && string.IsNullOrWhiteSpace(defaultValueSql) && defaultValue == null)
var valueGenerationStrategy = annotatable[MySqlAnnotationNames.ValueGenerationStrategy] as MySqlValueGenerationStrategy?;
if ((valueGenerationStrategy == MySqlValueGenerationStrategy.IdentityColumn || property.ValueGenerated == ValueGenerated.OnAdd) && string.IsNullOrWhiteSpace(defaultValueSql) && defaultValue == null)
{
switch (matchType)
{
Expand All @@ -387,35 +387,34 @@ protected override void ColumnDefinition([CanBeNull] string schema, [NotNull] st
autoIncrement = true;
break;
case "datetime":
if (_options.ConnectionSettings.ServerVersion.SupportsDateTime6)
if (!_options.ConnectionSettings.ServerVersion.SupportsDateTime6)
throw new InvalidOperationException(
$"Error in {table}.{name}: DATETIME does not support values generated " +
"on Add or Update in MySql <= 5.5, try explicitly setting the column type to TIMESTAMP");
$"Error in {table}.{name}: DATETIME does not support values generated " +
"on Add or Update in MySql <= 5.5, try explicitly setting the column type to TIMESTAMP");
goto case "timestamp";
case "timestamp":
defaultValueSql = $"CURRENT_TIMESTAMP({matchLen})";
break;
}
}

string onUpdateSql = null;

//if (property.ValueGenerated == ValueGenerated.OnAddOrUpdate)
//{
// switch (matchType)
// {
// case "datetime":
// if (_options.ConnectionSettings.ServerVersion.SupportsDateTime6)
// throw new InvalidOperationException($"Error in {table}.{name}: DATETIME does not support values generated " +
// "on Add or Update in MySql <= 5.5, try explicitly setting the column type to TIMESTAMP");
// goto case "timestamp";
// case "timestamp":
// if (string.IsNullOrWhiteSpace(defaultValueSql) && defaultValue == null)
// defaultValueSql = $"CURRENT_TIMESTAMP({matchLen})";
// onUpdateSql = $"CURRENT_TIMESTAMP({matchLen})";
// break;
// }
//}
if (property.ValueGenerated == ValueGenerated.OnAddOrUpdate)
{
switch (matchType)
{
case "datetime":
if (!_options.ConnectionSettings.ServerVersion.SupportsDateTime6)
throw new InvalidOperationException($"Error in {table}.{name}: DATETIME does not support values generated " +
"on Add or Update in MySql <= 5.5, try explicitly setting the column type to TIMESTAMP");
goto case "timestamp";
case "timestamp":
if (string.IsNullOrWhiteSpace(defaultValueSql) && defaultValue == null)
defaultValueSql = $"CURRENT_TIMESTAMP({matchLen})";
onUpdateSql = $"CURRENT_TIMESTAMP({matchLen})";
break;
}
}

builder
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(name))
Expand Down
6 changes: 3 additions & 3 deletions src/EFCore.MySql/Storage/Internal/MySqlDatabaseCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public override void Create()
}

protected override bool HasTables()
=> Dependencies.ExecutionStrategyFactory.Create().Execute(_connection, connection => (int)CreateHasTablesCommand().ExecuteScalar(connection) != 0);
=> Dependencies.ExecutionStrategyFactory.Create().Execute(_connection, connection => (long)CreateHasTablesCommand().ExecuteScalar(connection) != 0);

protected override Task<bool> HasTablesAsync(CancellationToken cancellationToken = default(CancellationToken))
=> Dependencies.ExecutionStrategyFactory.Create().ExecuteAsync(_connection,
async (connection, ct) => (int)await CreateHasTablesCommand().ExecuteScalarAsync(connection, cancellationToken: ct).ConfigureAwait(false) != 0, cancellationToken);
async (connection, ct) => (long)await CreateHasTablesCommand().ExecuteScalarAsync(connection, cancellationToken: ct).ConfigureAwait(false) != 0, cancellationToken);

private IRelationalCommand CreateHasTablesCommand()
=> _rawSqlCommandBuilder
Expand Down Expand Up @@ -202,4 +202,4 @@ private IReadOnlyList<MigrationCommand> CreateDropCommands()
// invalid connection may now be valid.
private void ClearPool() => MySqlConnection.ClearPool(_connection.DbConnection as MySqlConnection);
}
}
}

2 comments on commit 4b3ec79

@yukozh
Copy link
Member

@yukozh yukozh commented on 4b3ec79 Jun 28, 2017

Choose a reason for hiding this comment

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

Does migrations work now?

@caleblloyd
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Next I need to fix ModificationCommandBatch

Please sign in to comment.