Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fixes #2018 SelectingGeneratorAccessor cannot find Alternative Identi… #2023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 29, 2025
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
4 changes: 2 additions & 2 deletions 4 samples/FluentMigrator.Example.Migrations/1_AddGTDTables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public override void Up()
.WithColumn("IsAdmin").AsBoolean().NotNullable();


IfDatabase(ProcessorId.SqlServer).
IfDatabase(ProcessorIdConstants.SqlServer).
Create.Index("IX_Users").OnTable("Users")
.OnColumn("Name").Ascending()
.WithOptions().NonClustered()
.Include("Login")
.Include("IsAdmin");

IfDatabase(processorId => processorId != ProcessorId.SqlServer)
IfDatabase(processorId => processorId != ProcessorIdConstants.SqlServer)
.Create.Index("IX_Users").OnTable("Users")
.OnColumn("Name").Ascending()
.WithOptions().NonClustered();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static DatabaseConfiguration CreateSqliteConfiguration()

return new DatabaseConfiguration
{
ProcessorId = ProcessorId.SQLite,
ProcessorId = ProcessorIdConstants.SQLite,
ConnectionString = csb.ConnectionString,
};
}
Expand All @@ -64,7 +64,7 @@ private static DatabaseConfiguration CreateSqlServerConfiguration()

return new DatabaseConfiguration
{
ProcessorId = ProcessorId.SqlServer,
ProcessorId = ProcessorIdConstants.SqlServer,
ConnectionString = scsb.ToString()
};
}
Expand Down
2 changes: 1 addition & 1 deletion 2 samples/FluentMigrator.Example.Migrator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private static DatabaseConfiguration CreateDatabaseConfiguration(CommandOption p
{
return new DatabaseConfiguration
{
ProcessorId = ProcessorId.SQLite,
ProcessorId = ProcessorIdConstants.SQLite,
ConnectionString = connectionString.Value(),
};
}
Expand Down
12 changes: 12 additions & 0 deletions 12 src/FluentMigrator.Abstractions/IMigrationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
//
#endregion

using System.Collections.Generic;

using FluentMigrator.Expressions;
using FluentMigrator.Runner.Generators;

Expand All @@ -30,6 +32,16 @@ public interface IMigrationGenerator
/// Provides the Quoter used by the migration generator.
/// </summary>
IQuoter Quoter { get; }

/// <summary>
/// The ID of the generator.
/// </summary>
string GeneratorId { get; }

/// <summary>
/// The alternative ID of the generator.
/// </summary>
List<string> GeneratorIdAliases { get; }

/// <summary>
/// Generates a <c>CREATE SCHEMA</c> SQL statement
Expand Down
5 changes: 5 additions & 0 deletions 5 src/FluentMigrator.Console/MigratorConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,19 @@ private static IServiceCollection CreateCoreServices()
.AddDotConnectOracle12C()
.AddFirebird()
.AddHana()
.AddMySql()
.AddMySql4()
.AddMySql5()
.AddMySql8()
.AddOracle()
.AddOracle12C()
.AddOracleManaged()
.AddOracle12CManaged()
.AddPostgres()
.AddPostgres92()
.AddPostgres10_0()
.AddPostgres11_0()
.AddPostgres15_0()
.AddRedshift()
.AddSnowflake()
.AddSQLite()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
//
#endregion

using System.Collections.Generic;

using FluentMigrator.Expressions;

namespace FluentMigrator.Runner.Generators.Base
Expand All @@ -33,6 +35,12 @@ public GeneratorBase(IColumn column, IQuoter quoter, IDescriptionGenerator descr
_descriptionGenerator = descriptionGenerator;
}

/// <inheritdoc />
public abstract string GeneratorId { get; }

/// <inheritdoc />
public abstract List<string> GeneratorIdAliases { get; }

public abstract string Generate(CreateSchemaExpression expression);
public abstract string Generate(DeleteSchemaExpression expression);
public abstract string Generate(CreateTableExpression expression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ private IMigrationGenerator FindGenerator(
{
foreach (var generator in generators)
{
if (string.Equals(generator.GeneratorId, generatorId, StringComparison.OrdinalIgnoreCase))
return generator;
if (generator.GeneratorIdAliases.Any(g => string.Equals(g, generatorId, StringComparison.OrdinalIgnoreCase)))
return generator;
if (string.Equals(GetName(generator), generatorId, StringComparison.OrdinalIgnoreCase))
return generator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
namespace FluentMigrator.Runner.Processors
{
/// <summary>
/// An <see cref="IProcessorAccessor"/> implementation that selects one generator by name
/// An <see cref="IProcessorAccessor"/> implementation that selects one processor by name
/// </summary>
public class SelectingProcessorAccessor : IProcessorAccessor
{
Expand Down Expand Up @@ -58,16 +58,20 @@ public SelectingProcessorAccessor(
{
// No generator selected
if (procs.Count == 0)
{
throw new ProcessorFactoryNotFoundException("No migration processor registered.");
}

if (procs.Count > 1)
{
throw new ProcessorFactoryNotFoundException("More than one processor registered, but no processor id given. Specify the processor id by configuring SelectingProcessorAccessorOptions.");
}
foundProcessor = procs.Single();
//(Processor as ProcessorBase).Generator
}
else
{
// One of multiple generators
foundProcessor = FindGenerator(procs, processorId);
foundProcessor = FindProcessor(procs, processorId);
}

// Special handling when no connection string could be found
Expand All @@ -77,7 +81,7 @@ public SelectingProcessorAccessor(
{
if (foundProcessor is ProcessorBase processorBase)
{
var databaseIds = new List<string>() { processorBase.DatabaseType };
var databaseIds = new List<string> { processorBase.DatabaseType };
databaseIds.AddRange(processorBase.DatabaseTypeAliases);

var processorOptions = serviceProvider.GetRequiredService<IOptionsSnapshot<ProcessorOptions>>();
Expand All @@ -96,27 +100,27 @@ public SelectingProcessorAccessor(
public IMigrationProcessor Processor { get; }

[NotNull]
private IMigrationProcessor FindGenerator(
private IMigrationProcessor FindProcessor(
[NotNull, ItemNotNull] IReadOnlyCollection<IMigrationProcessor> processors,
[NotNull] string processorsId)
[NotNull] string processorId)
{
foreach (var processor in processors)
{
if (string.Equals(processor.DatabaseType, processorsId, StringComparison.OrdinalIgnoreCase))
if (string.Equals(processor.DatabaseType, processorId, StringComparison.OrdinalIgnoreCase))
return processor;
}

foreach (var processor in processors)
{
foreach (var databaseTypeAlias in processor.DatabaseTypeAliases)
{
if (string.Equals(databaseTypeAlias, processorsId, StringComparison.OrdinalIgnoreCase))
if (string.Equals(databaseTypeAlias, processorId, StringComparison.OrdinalIgnoreCase))
return processor;
}
}

var generatorNames = string.Join(", ", processors.Select(p => p.DatabaseType).Union(processors.SelectMany(p => p.DatabaseTypeAliases)));
throw new ProcessorFactoryNotFoundException($@"A migration generator with the ID {processorsId} couldn't be found. Available generators are: {generatorNames}");
var processorNames = string.Join(", ", processors.Select(p => p.DatabaseType).Union(processors.SelectMany(p => p.DatabaseTypeAliases)));
throw new ProcessorFactoryNotFoundException($@"A migration processor with the ID {processorId} couldn't be found. Available processors are: {processorNames}");
}

private class PassThroughGeneratorAccessor : IGeneratorAccessor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region License
#region License
// Copyright (c) 2018, Fluent Migrator Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -22,7 +22,7 @@ namespace FluentMigrator.Runner.Processors
public class SelectingProcessorAccessorOptions
{
/// <summary>
/// The ID of the generator to be returned by the <see cref="SelectingProcessorAccessor"/>
/// The ID of the processor to be returned by the <see cref="SelectingProcessorAccessor"/>
/// </summary>
public string ProcessorId { get; set; }
}
Expand Down
6 changes: 6 additions & 0 deletions 6 src/FluentMigrator.Runner.Db2/Generators/Db2/Db2Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ public override string Generate(Expressions.CreateIndexExpression expression)
columnList);
}

/// <inheritdoc />
public override string GeneratorId => GeneratorIdConstants.DB2;

/// <inheritdoc />
public override List<string> GeneratorIdAliases => new List<string> { GeneratorIdConstants.DB2 };

public override string Generate(Expressions.CreateSchemaExpression expression)
{
return string.Format("CREATE SCHEMA {0}", Quoter.QuoteSchemaName(expression.SchemaName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// limitations under the License.
#endregion

using System.Collections.Generic;

using Microsoft.Extensions.Options;

namespace FluentMigrator.Runner.Generators.DB2.iSeries
Expand All @@ -37,5 +39,11 @@ public Db2ISeriesGenerator(
: base(quoter, generatorOptions)
{
}

/// <inheritdoc />
public override string GeneratorId => GeneratorIdConstants.Db2ISeries;

/// <inheritdoc />
public override List<string> GeneratorIdAliases => new List<string> { GeneratorIdConstants.Db2ISeries, GeneratorIdConstants.DB2 };
}
}
4 changes: 2 additions & 2 deletions 4 src/FluentMigrator.Runner.Db2/Processors/Db2/Db2Processor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public Db2Processor(
Quoter = quoter;
}

public override string DatabaseType => ProcessorId.DB2;
public override string DatabaseType => ProcessorIdConstants.DB2;

public override IList<string> DatabaseTypeAliases { get; } = new List<string> { "IBM DB2" };
public override IList<string> DatabaseTypeAliases { get; } = new List<string> { ProcessorIdConstants.IbmDb2, ProcessorIdConstants.DB2 };

public IQuoter Quoter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public Db2ISeriesProcessor(
Quoter = quoter;
}

public override string DatabaseType => "DB2 iSeries";
public override string DatabaseType => ProcessorIdConstants.Db2ISeries;

public override IList<string> DatabaseTypeAliases { get; } = new List<string> { "IBM DB2 iSeries", "DB2" };
public override IList<string> DatabaseTypeAliases { get; } = new List<string> { ProcessorIdConstants.IbmDb2ISeries, ProcessorIdConstants.DB2 };

public IQuoter Quoter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

Expand Down Expand Up @@ -166,6 +167,12 @@ public string GenerateAlterSequence(SequenceDefinition sequence)
return string.Empty;
}

/// <inheritdoc />
public override string GeneratorId => GeneratorIdConstants.Firebird;

/// <inheritdoc />
public override List<string> GeneratorIdAliases => new List<string> { GeneratorIdConstants.Firebird };

public override string Generate(CreateTableExpression expression)
{
Truncator.Truncate(expression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public FirebirdProcessor(
ClearDDLFollowers();
}

public override string DatabaseType => ProcessorId.Firebird;
public override string DatabaseType => ProcessorIdConstants.Firebird;

public override IList<string> DatabaseTypeAliases { get; } = new List<string>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//
#endregion

using System.Collections.Generic;
using System.Linq;
using System.Text;

Expand Down Expand Up @@ -159,6 +160,12 @@ public override string Generate(UpdateDataExpression expression)
return string.Format("{0};", base.Generate(expression));
}

/// <inheritdoc />
public override string GeneratorId => GeneratorIdConstants.Hana;

/// <inheritdoc />
public override List<string> GeneratorIdAliases => new List<string> { GeneratorIdConstants.Hana };

public override string Generate(CreateTableExpression expression)
{
var descriptionStatements = DescriptionGenerator.GenerateDescriptionStatements(expression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public HanaProcessor(
{
}

public override string DatabaseType => ProcessorId.Hana;
public override string DatabaseType => ProcessorIdConstants.Hana;

public override IList<string> DatabaseTypeAliases { get; } = new List<string>();

Expand Down
8 changes: 8 additions & 0 deletions 8 src/FluentMigrator.Runner.Jet/Generators/Jet/JetGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.Generic;

using FluentMigrator.Expressions;
using FluentMigrator.Runner.Generators.Generic;

Expand Down Expand Up @@ -44,6 +46,12 @@ public override string Generate(AlterDefaultConstraintExpression expression)
return CompatibilityMode.HandleCompatibility("Altering of default constraints is not supported for Jet");
}

/// <inheritdoc />
public override string GeneratorId => GeneratorIdConstants.Jet;

/// <inheritdoc />
public override List<string> GeneratorIdAliases => new List<string> { GeneratorIdConstants.Jet };

public override string Generate(DeleteTableExpression expression)
{
if (expression.IfExists)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public JetProcessor(
[Obsolete]
public override string ConnectionString { get; }

public override string DatabaseType { get; } = ProcessorId.Jet;
public override string DatabaseType { get; } = ProcessorIdConstants.Jet;

public override IList<string> DatabaseTypeAliases { get; } = new List<string>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#endregion

using System;
using System.Collections.Generic;
using System.Linq;

using FluentMigrator.Expressions;
Expand Down Expand Up @@ -63,7 +64,12 @@ protected MySql4Generator(

public override string AlterColumn { get { return "ALTER TABLE {0} MODIFY COLUMN {1}"; } }
public override string DeleteConstraint { get { return "ALTER TABLE {0} DROP {1}{2}"; } }
//public override string DeleteConstraint { get { return "ALTER TABLE {0} DROP FOREIGN KEY {1}"; } }

/// <inheritdoc />
public override string GeneratorId => GeneratorIdConstants.MySql4;

/// <inheritdoc />
public override List<string> GeneratorIdAliases => [GeneratorIdConstants.MySql4, GeneratorIdConstants.MySql];

public override string Generate(CreateTableExpression expression)
{
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.