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
42 changes: 11 additions & 31 deletions src/EFCore.Jet/Migrations/Internal/JetHistoryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

using System;
using System.Text;
using EntityFrameworkCore.Jet.Internal;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Migrations;
using EntityFrameworkCore.Jet.Utilities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;

namespace EntityFrameworkCore.Jet.Migrations.Internal
{
Expand Down Expand Up @@ -51,7 +54,7 @@ protected override string ExistsSql

var builder = new StringBuilder();
builder
.Append("SHOW TABLES WHERE NAME=")
.Append("SELECT * FROM `INFORMATION_SCHEMA.TABLES` WHERE `TABLE_NAME` = ")
.Append(stringTypeMapping.GenerateSqlLiteral(TableName));

return builder.ToString();
Expand Down Expand Up @@ -131,7 +134,7 @@ public override string GetCreateIfNotExistsScript()
var stringTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string));

builder
.Append("IF NOT EXISTS (SELECT * FROM (SHOW TABLES) WHERE Name = ")
.Append("IF NOT EXISTS (SELECT * FROM `INFORMATION_SCHEMA.TABLES` WHERE `TABLE_NAME` = ")
.Append(stringTypeMapping.GenerateSqlLiteral(TableName))
.Append(") THEN ");
using (builder.Indent())
Expand All @@ -151,20 +154,7 @@ public override string GetCreateIfNotExistsScript()
/// </summary>
public override string GetBeginIfNotExistsScript(string migrationId)
{
Check.NotEmpty(migrationId, nameof(migrationId));

var stringTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string));

return new StringBuilder()
.Append("IF NOT EXISTS(SELECT * FROM ")
.Append(SqlGenerationHelper.DelimitIdentifier(TableName))
.Append(" WHERE ")
.Append(SqlGenerationHelper.DelimitIdentifier(MigrationIdColumnName))
.Append(" = ")
.Append(stringTypeMapping.GenerateSqlLiteral(migrationId))
.AppendLine(")")
.Append("THEN")
.ToString();
throw new NotSupportedException(JetStrings.MigrationScriptGenerationNotSupported);
}

/// <summary>
Expand All @@ -175,20 +165,7 @@ public override string GetBeginIfNotExistsScript(string migrationId)
/// </summary>
public override string GetBeginIfExistsScript(string migrationId)
{
Check.NotEmpty(migrationId, nameof(migrationId));

var stringTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string));

return new StringBuilder()
.Append("IF EXISTS(SELECT * FROM ")
.Append(SqlGenerationHelper.DelimitIdentifier(TableName))
.Append(" WHERE ")
.Append(SqlGenerationHelper.DelimitIdentifier(MigrationIdColumnName))
.Append(" = ")
.Append(stringTypeMapping.GenerateSqlLiteral(migrationId))
.AppendLine(")")
.Append("THEN")
.ToString();
throw new NotSupportedException(JetStrings.MigrationScriptGenerationNotSupported);
}

/// <summary>
Expand All @@ -197,6 +174,9 @@ public override string GetBeginIfExistsScript(string migrationId)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override string GetEndIfScript() => ";" + Environment.NewLine;
public override string GetEndIfScript()
{
throw new NotSupportedException(JetStrings.MigrationScriptGenerationNotSupported);
}
}
}
6 changes: 6 additions & 0 deletions src/EFCore.Jet/Properties/JetStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/EFCore.Jet/Properties/JetStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="MigrationScriptGenerationNotSupported" xml:space="preserve">
<value>Generating idempotent scripts for migration is not currently supported by Jet. For more information, see https://github.com/bubibubi/EntityFrameworkCore.Jet/wiki.</value>
</data>
<data name="IdentityBadType" xml:space="preserve">
<value>Identity value generation cannot be used for the property '{property}' on entity type '{entityType}' because the property type is '{propertyType}'. Identity value generation can only be used with signed integer properties.</value>
</data>
Expand Down